|
|
卖萌的紫菜汤 · 如何从日期中获取微秒数?开发者社区· 3 月前 · |
|
|
怕考试的炒粉 · 秋凉老师跨界巨制震撼上线:PHOTOSHOP ...· 1 年前 · |
|
|
温暖的煎饼 · 没有比赛也要纪念?Arai推出2020年曼岛 ...· 2 年前 · |
|
|
豪气的移动电源 · 【AION S】埃安_AION ...· 2 年前 · |
|
|
坚韧的凉面 · 4本图神经网络中文书籍的比较_图神经网络书籍 ...· 3 年前 · |
|
|
谦逊的面包 · 甄嬛传Q版 - 🌈️包子漫畫· 3 年前 · |
我想用下面的方法从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能够同时解析字符串和字符串数组