Trailing slash automatically removed when using basePath and url has query params
See original GitHub issueWhat version of Next.js are you using?
11.0.1
What version of Node.js are you using?
12.16.1
What browser are you using?
Chrome 92.0.4515.131
What operating system are you using?
macOS Big Sur
How are you deploying your application?
next build && next export, static files on AWS S3
Describe the Bug
When URL has query params, e. g. mydomain.com/basePath/?params=1 it automatically removes slash and comes to mydomain.com/basePath?params=1
This is affecting our analytics.
It happens only when basePath is configured. We have tested and slash persists without basePath and without query params
Expected Behavior
We would like all URL’s to end with a /, even it has query params. Because it affect to analytics and for internal links.
To Reproduce
next.config.js:
{
...
basePath: '/base-path',
trailingSlash: true,
...
}
And write to URL any query params after slash and hit enter For example go to domain.com/base-path/?query=true it comes to domain.com/base-path?query=true
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Strip trailing slash doesn't take into account query or hash in ...
Currently if you have a a trailing slash and a query parameter, the trailing slash is not being removed. Expected behavior
Read more >Remove trailing slash at the end of axios url request
I am trying to do a request with axios ...
Read more >Is a trailing slash appropriate before URL parameters?
Both versions of your URL with parameters are "legal". The trailing slash can be there if you choose, or you can omit it....
Read more >Automatically adding trailing slash at the end of the REST API ...
My apps started failing with the error "Invalid Argument", and it seems like Retool is adding a trailing slash ("/") at the end...
Read more >Trailing Slash - next.config.js
By default Next.js will redirect urls with trailing slashes to their counterpart without a trailing slash. For example /about/ will redirect to /about...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
hi @IhorVoit!
from what do I see in the code the router is not respecting the
trailingSlash
config in the functionaddPathPrefix
when thepath
is like/?asd=asd
, then the/
is stripped out frompath
without checking thetrailingSlash
, and then is concatenated with thebasePath
, so in result, it ends like/base-path?asd=asd
instead of/base-path/?asd=asd
. Also, it only happens for the root path/
, the dynamic pages, and others like/about
are working fine.@ijjk fyi
Hi, @ijjk! Thanks a lot, problem solved! Can I use this version of package in production or should I wait for next stable version?