需要讨论带有浅选项的动态路由下一个JS

时间:2020-07-21 06:33:07

标签: javascript reactjs next.js server-side-rendering vercel

每次尝试使用浅选项在URL中更新或添加queryParms时,页面都会呈现。有时会出错

提供的as值(null)与href值(/ search / [country] / [city])不兼容

对于动态路由,我的文件夹结构为

Search -> Folder Name
   - [country]
     -  [city].js

当我尝试更新点击时的网址

  const incrementCounter = () => {
     const currentCounter = query.counter ? parseInt(query.counter) : 0;
    const href = `/search/de/berlin/?counter=${currentCounter + 1}`;
    router.push(pathname, href, { shallow: true });
  };

enter image description here

就我而言,在单击更改状态计数器时,路由器中的查询对象未使用计数器params.so更新,因此,如果我再次单击,则它不会递增。

第二种情况,如果我将路径名替换为asPath,那么我的URL正在更新,而查询参数也在更新。问题是页面每次在服务器上呈现。

要复制

重现行为的步骤:

codesandbox url

  1. 第/ search / de / berlin页
  2. 点击更改状态计数器
  3. 查看渲染页面,但不更新url
  4. 看到错误

预期行为

我当前的网址-http://localhost:4000/search/de/berlin 想要添加新的queryParams:?counter=3&id=98

不应在服务器上重新加载页面。应该是路由器查询中的所有参数。

系统信息

  • Next.js版本:最新
  • Node.js版本:最新

0 个答案:

没有答案