qwik icon indicating copy to clipboard operation
qwik copied to clipboard

[🐞] `trailingSlash:false` doesn't effect at the root path with query string.

Open genki opened this issue 2 years ago • 3 comments

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

genki avatar Aug 29 '23 02:08 genki

Sorry, can you be more specific on how to reproduce this?

What do I click on? What is expected? What happens instead.

mhevery avatar Aug 30 '23 00:08 mhevery

@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.

genki avatar Aug 30 '23 22:08 genki

I'll do it

JerryWu1234 avatar Oct 15 '24 03:10 JerryWu1234

Image Image

it seems that the last slash can't disappear when the pathname is /.

JerryWu1234 avatar Oct 24 '24 10:10 JerryWu1234

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 avatar Oct 25 '24 03:10 JerryWu1234

@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 avatar Oct 28 '24 11:10 wmertens

image

@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.

JerryWu1234 avatar Oct 30 '24 03:10 JerryWu1234

@wmertens Do you have any clues about this PR? We can do it

JerryWu1234 avatar Nov 04 '24 08:11 JerryWu1234

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

JerryWu1234 avatar Feb 13 '25 02:02 JerryWu1234

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

wmertens avatar Feb 13 '25 10:02 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

----————————————————————————————————

JerryWu1234 avatar Feb 13 '25 10:02 JerryWu1234

I'm going to close this issue because URLs must always have at least a / at the beginning of the pathname. @wmertens @genki

JerryWu1234 avatar Feb 13 '25 10:02 JerryWu1234