![]() |
聪明的炒粉 · 《关于促进全省党政机关带头推广使用新能源汽车 ...· 7 月前 · |
![]() |
卖萌的松树 · 千玺胡先煦罗一舟考进国家话剧院,却遭质疑,为 ...· 8 月前 · |
![]() |
力能扛鼎的夕阳 · 新发展理念引领发展新时代――关于树立创新、协 ...· 8 月前 · |
![]() |
成熟的橡皮擦 · 少林秘谱:三十六抓解脱法释秘_敌人_对方_头发· 1 年前 · |
![]() |
逆袭的甘蔗 · 2024考研小白,大家都是怎么找百度网盘资料 ...· 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 年前 |