Next.js: When using rewrites, client asPath is sliced by the basePath's length even when basePath config is false

Created on 1 Aug 2020  路  5Comments  路  Source: vercel/next.js

Bug report

Describe the bug

We're trying to implement basePath in our repo and it works until we want to exclude any paths using rewrites in our config. When using rewrites we find that asPath is shortened by the basePath's length even though we've set basePath to false. It appears that asPath works correctly on server, but not on the client.

To Reproduce

Using the following config, visit /diets and see asPath is "ts" instead of the expected "/diets". Tried with both /web/diets and /diets as destination, both produce the same problem.

// next.config.js

basePath: '/web',
rewrites: () => [
  {
    source: '/diets',
    destination: '/diets',
    basePath: false,
  }]

Expected behavior

I expect the asPath to be "/diets"

See this file:

Line 41: packages/next/next-server/lib/router/router.ts <-- method that's slicing asPath
Line 64: packages/next/client/index.js <-- client does not check the config for basePath before slicing asPath

Screenshots

image

System information

  • Version of Next.js: 9.5.0
  • Version of Node.js: 12.16.0

Additional context

Add any other context about the problem here.

bug

All 5 comments

@sallomendo

Thank you for such a fast turnaround 馃槏

Please try out next@^9.5.2-canary.2 with the fix!

I can confirm that the issue has been resolved, thanks!

@Timer thank you! We're anxiously awaiting the official release of 9.5.2 馃槃

Was this page helpful?
0 / 5 - 0 ratings