小编Shy*_*yam的帖子

在 Next.js 中使用查询参数创建 url

我想通过以下方式从查询参数创建一个 url:

 router.push(
      {
        pathname: '/cars',
        query: colors + type + price,

      },
      undefined,
      {
        shallow: true,
      },
  );
Run Code Online (Sandbox Code Playgroud)

const colors = ['red', 'blue', 'yellow']; //the arrays could contain many others values
const type = ['offroad', 'sport'];
const price = 'hight'  //this is a string
Run Code Online (Sandbox Code Playgroud)

我想实现,当我单击触发的按钮时router.push,下一个: /cars?color=red,yellow,blue&type=offroad,sport&price=hight

reactjs next.js

8
推荐指数
2
解决办法
3万
查看次数

标签 统计

next.js ×1

reactjs ×1