Inconsistent basename behavior between Components and Middleware in Framework Mode
#14851
Unanswered
KimotoYanke
asked this question in
Q&A
Replies: 1 comment
-
|
@KimotoYanke Your observation is reasonable: basename-aware URL generation in components and explicit middleware redirects are not always symmetrical by default. A practical pattern is to centralize redirect URL creation (for example a helper that prefixes So yes, your workaround style is generally the right defensive approach until middleware basename behavior is unified. Sources: |
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.
-
Hi.
My team is developing a project using Framework mode with a
basenameconfigured in the URL. We're running into an issue wherebasenameis handled inconsistently depending on context.Reproduction repository: https://github.com/KimotoYanke/react-router-basename-test (basename is set to
/base/)Current Behavior
In components, basename is handled automatically and transparently. For example, a
<Link>ornavigate()call targeting the login page can be written simply as/login, and React Router correctly resolves it to/base/login.However, in middleware,
throw redirect("/login")does not apply the basename — it redirects to/logininstead of/base/login, resulting in a not-found error. As a workaround, we have to writethrow redirect(joinURL(import.meta.env.BASE_URL, "login"))Questions
basenameto redirect paths?basenamehandling?I'd appreciate any clarification. Thank you!
Beta Was this translation helpful? Give feedback.
All reactions