【问题标题】:Next js changes query params in urlNext js 更改 url 中的查询参数
【发布时间】:2021-02-09 18:37:26
【问题描述】:

点击next.js中的按钮后,我想在url参数中添加数据

  function send() {
    router.push(
      { pathname: "/", query: { n: "firstparam,secondparam" } },
      undefined,
      {
        shallow: true
      }
    );
  }

点击后进入网址:

site/?n=firstparam%2Csecondparam

所以,nextjs 代替了,,添加了%2C。如何在不使用replace()?like:site/?n=firstparam,secondparam
的情况下避免所有这些迹象并获得有效的网址 演示:https://codesandbox.io/s/vibrant-sinoussi-d9z77?file=/pages/index.js

【问题讨论】:

    标签: next.js


    【解决方案1】:

    %2C,的url编码,Next.js的做法是正确的,因为,不是有效字符。

    console.log(encodeURIComponent(','))

    您可以尝试将 url 作为字符串传递。

    function send() {
      router.push('/?n=firstparam,secondparam', undefined, {
        shallow: true,
      });
    }
    
    猜你喜欢
    • 2016-02-29
    • 2021-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-12
    • 2020-06-17
    相关资源
    最近更新 更多