When using rewrites, client asPath is sliced by the basePath's length even when basePath config is false
See original GitHub issueBug 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
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.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (2 by maintainers)
Top GitHub Comments
I can confirm that the issue has been resolved, thanks!
Please try out
next@^9.5.2-canary.2
with the fix!