|
|
星星上的墨镜 · 使用Qt在Windows中构建用于Linux ...· 2 周前 · |
|
|
睡不着的酸菜鱼 · 开学啦,同学们,欢迎回来!_卓雅· 1 年前 · |
|
|
鬼畜的仙人掌 · List Series DataFrame ...· 1 年前 · |
|
|
聪明伶俐的课本 · “南水北调、西气东输、青藏铁路、西电东送”四 ...· 1 年前 · |
|
|
飞翔的酸菜鱼 · 指数回落,全球经济复苏趋势放缓——2021年 ...· 1 年前 · |
|
|
大方的香烟 · Class Activation ...· 1 年前 · |
我想用下面的方法从query params创建一个url:
router.push(
pathname: '/cars',
query: colors + type + price,
undefined,
shallow: true,
);
const colors = ['red', 'blue', 'yellow']; //the arrays could contain many others values
const type = ['offroad', 'sport'];
const price = 'hight' //this is a string
我想实现,当我点击触发
router.push
的按钮时,下一步:
/cars?color=red,yellow,blue&type=offroad,sport&price=hight
https://nextjs.org/docs/api-reference/next/router#with-url-object
你试试这个
router.push({
pathname: '/cars',
query: {
colors: colors.join(","),
types: types.join(",")
})
您可以简单地这样做:
const router = useRouter();
router.push(
pathname: '/cars',
query: {
colors,
type,
price,
undefined,
shallow: true,
},
);
根据Next/Router类型,查询类型为
ParsedUrlQuery
类型,相当于
interface ParsedUrlQuery extends NodeJS.Dict<string | string[]> { }
也就是说,next/router能够同时解析字符串和字符串数组
|
|
睡不着的酸菜鱼 · 开学啦,同学们,欢迎回来!_卓雅 1 年前 |