[Start] Bare basepath URL (e.g. /preview) redirects to /preview/ on SSR even with trailingSlash: 'never' #7282
Replies: 2 comments
-
|
Hey @schiller-manuel, Thanks |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
moved this into this issue: #7291 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
When
basepathis set on the router (e.g./preview) and a user visits the bare basepath URL (http://localhost:3000/preview), the SSR handler issues a redirect tohttp://localhost:3000/preview/(with trailing slash). This happens even thoughtrailingSlashdefaults to"never".Visiting
/with no basepath does not redirect to/-with-anything, so the behavior is asymmetric.Where it happens
In
packages/router-core/src/router.tsbeforeLoad, on the server, the router rebuilds the location and comparespublicHref:Walkthrough for request
GET /previewwithbasepath: "/preview":latestLocation.pathname=/.buildLocation({ to: "/" })re-joins basepath +/→ produces/preview/.publicHref=/preview, rebuiltpublicHref=/preview/→ mismatch → 308 redirect.Root case (no basepath): both incoming and rebuilt are
/, so no redirect. That is why root "just works" but a bare basepath does not.Expected
With
trailingSlash: "never"(the default),GET /previewshould be served as the canonical URL — no redirect to/preview/.Repro
basepath: "/preview"in the router config (and matching dev server base/routerBasepath)http://localhost:3000/preview→ 308 →http://localhost:3000/preview/Related
/redirects to/basepath/), but the bare-basepath case here looks distinct.Question
Is this intentional canonicalization (treat bare basepath as non-canonical), or a bug where
trailingSlashis not applied to the rebuiltpublicHrefbefore the equality check?Versions:
@tanstack/react-router@1.167.5,@tanstack/react-start@1.166.18.Beta Was this translation helpful? Give feedback.
All reactions