question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Trailing slash automatically removed when using basePath and url has query params

See original GitHub issue

What 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:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
LetItRockcommented, Aug 10, 2021

hi @IhorVoit!

from what do I see in the code the router is not respecting the trailingSlash config in the function addPathPrefix when the path is like /?asd=asd, then the / is stripped out from path without checking the trailingSlash, and then is concatenated with the basePath, 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

1reaction
IhorVoitcommented, Sep 22, 2021

Hi, @ijjk! Thanks a lot, problem solved! Can I use this version of package in production or should I wait for next stable version?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found