[🐞] `trailingSlash:false` doesn't effect at the root path with query string.
Which component is affected?
Qwik City (routing)
Describe the bug
Configured the Qwik City as qwikCity({trailingSlash:false}) in vite config, all routes turned to be without the trailing slash except the root path with query string.
The URL like this https://example.com?foo=bar is redirected to https://example.com/?foo=bar
although https://example.com and https://example.com/todo?foo=bar doesn't.
I think this is not consistent.
Reproduction
https://stackblitz.com/edit/qwik-starter-znqffd?file=src%2Froutes%2Findex.tsx
Steps to reproduce
See the top page and "demo" page linked from the top page.
These two pages show the loc.url at the top.
Due to the stackblitz's behaviour, we need to reload for each page view to show the real url.
As we cannot see the real address bar, the behaviour of the reproduction is slightly different from the real.
System Info
System:
OS: macOS 13.4.1
CPU: (8) arm64 Apple M2
Memory: 87.33 MB / 24.00 GB
Shell: 3.6.1 - /opt/homebrew/bin/fish
Binaries:
Node: 20.5.0 - /opt/homebrew/bin/node
Yarn: 1.22.19 - /opt/homebrew/bin/yarn
npm: 9.8.1 - /opt/homebrew/bin/npm
pnpm: 8.6.11 - /opt/homebrew/bin/pnpm
Browsers:
Chrome: 116.0.5845.110
Safari: 16.5.2
npmPackages:
@builder.io/partytown: ^0.8.0 => 0.8.0
undici: 5.22.1 => 5.22.1
vite: 4.4.7 => 4.4.7
Additional Information
No response
Sorry, can you be more specific on how to reproduce this?
What do I click on? What is expected? What happens instead.
@mhevery Sorry, it's difficult because the stackblitz has only a fake navigation bar so we can't see the real URL redirected to.
Could you use any of your qwik app to have configured that the trailingSlash:false?
And then append the query string in the navigation bar like thishttps://yourapp.com?foo=bar.
It will be redirected to https://yourapp.com/?foo=bar even if we have configured trailingSlash:false.
I expect to see https://yourapp.com?foo=bar in the navigation bar.
I'll do it
it seems that the last slash can't disappear when the pathname is /.
stackoverflow.com/a/2581514/529442
Note that the absolute path cannot be empty; if none is present in the original URI, it MUST be given as "/" (the server root).
My conclusion is that this isn't a bug from my understanding. My English isn't very good; please point out if anything is wrong.
@JerryWu1234 I think we should special-case this. The absolute path must at least be /, but the URL doesn't have to have a trailing /. Redirecting should not happen.
@wmertens
it looks like that the browser didn't support this feature.
I intercepted the routing jump of window.history.pushState and verified it in the simplest way. The URL in the browser only changes when a / is added.
@wmertens Do you have any clues about this PR? We can do it
I think we couldn't finish it because the specifications limit that https://example.com/?foo=bar must have a trailing slash, whether the trailingSlash is false or not.
@genki @wmertens
So can we clarify what works and doesn't work @JerryWu1234 @genki ?
URLs must always have at least a / at the beginning of the pathname.
so, http://foo.com doesn't exist, the browser will automatically make it into ``http://foo.com/`.
So, trailingSlash: false should support http://foo.com/?foo=bar and http://foo.com/todo?foo=bar
So can we clarify what works and doesn't work @JerryWu1234 @genki ?
URLs must always have at least a
/at the beginning of the pathname.so,
http://foo.comdoesn't exist, the browser will automatically make it into ``http://foo.com/`.So,
trailingSlash: falseshould supporthttp://foo.com/?foo=barandhttp://foo.com/todo?foo=bar
----————————————————————————————————
I'm going to close this issue because URLs must always have at least a / at the beginning of the pathname. @wmertens @genki