【问题标题】:Percent in url next jsurl下一个js的百分比
【发布时间】:2021-02-13 23:47:48
【问题描述】:

我想创建一个网址:

  const click = () => {
    router.push(
      {
        pathname:`/cars?{color}${doors}$`,
      },
      undefined,
      {
        shallow: true,
      },
  );

当我点击触发功能的按钮时,我在 url 中获得:/cars%3Fcolor=red&doors=5
如何创建这个网址:/cars?color=red&doors=5,?

【问题讨论】:

标签: reactjs next.js


【解决方案1】:

query 字符串不能是pathname 的一部分。 ?query 字符串与pathname 分隔开来;如果pathname包含 ?,它将被编码为%3F。这就是您看到此结果的原因。

试试这个:

router.push(
    {
        pathname: '/cars',
        query: { color, doors },
    },
    // ...
)

【讨论】:

  • 无论如何,在 url 中出现了其他不应该存在的标志,比如%26,我想得到这样的东西:/cars?color=red&doors=5,只是简单的标志而不是编码的 url,你知道 jow ?
  • 这只是&的URL编码,这也可能是由于没有正确地将pathnamequery字符串分开。您能否确认我发布的解决方案是否失败?
  • 是的,它没有给出想要的结果。你知道替代方案吗?
  • 你能帮忙吗? stackoverflow.com/questions/66410826/get-accesstoken-in-auth0。会有很大帮助
猜你喜欢
  • 1970-01-01
  • 2011-04-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-04-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多