Next.js: [9.5.3 - Rewrites] Navigating route with dynamic routes no longer work properly

Created on 3 Sep 2020  路  7Comments  路  Source: vercel/next.js

Describe the bug

// next.config.js
module.exports = {
  rewrites() {
    return [
      {
        source: "/my-post/:id",
        destination: "/post"
      }
    ];
  }
};

Navigating via Link or router.push

      <Link
        href={{
          pathname: "/post",
          query: {
            id: 1,
            another: "another"
          }
        }}
        as="/my-post/1?another=another"
      >
        <a>Post 1</a>
      </Link>

When custom the as path with params then router.query.id no longer true.

Actual: id=1?another=another
Expected: id=1

To Reproduce

https://codesandbox.io/s/aged-sky-nzs6j?file=/pages/index.js

bug 2 p0

All 7 comments

I also updated and all's broken now.

Hi, you should no longer need to map the href and as manually for custom-routes and next/link as they are being resolved automatically and the above snippet works ok if you only provide the href with the destination URL e.g.

<Link href="/my-post/1?another=another">
  <a>Post 1</a>
</Link>

I opened a PR to ensure this is being correctly resolved when mapping manually with href and as and automatically with only href here

This should be fixed in v9.5.4-canary.3 of Next.js please upgrade and try it out!

@ijjk I've /en/software.jsx and /en/[post].jsx files. When I navigated to /en/software/ via Router.push('/en/software/') in v9.5.2 it resolved to /en/software.jsx correctly. But in v9.5.3 and v9.5.4-canary.3 it resolves to /en/[post].jsx. Is this intentional change? And why in the minor releases do you change so things?

@MrEfrem I opened a new issue to track the specific issue you are encountering here

Hi, you should no longer need to map the href and as manually for custom-routes and next/link as they are being resolved automatically and the above snippet works ok if you only provide the href with the destination URL e.g.

<Link href="/my-post/1?another=another">
  <a>Post 1</a>
</Link>

I had tried this, but throw error 404 and auto reload page.
Link example: https://codesandbox.io/s/hungry-breeze-675gf?file=/pages/index.js

@nghiepit can you please try [email protected]?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

irrigator picture irrigator  路  3Comments

flybayer picture flybayer  路  3Comments

swrdfish picture swrdfish  路  3Comments

ghost picture ghost  路  3Comments

knipferrc picture knipferrc  路  3Comments