-
-
Notifications
You must be signed in to change notification settings - Fork 503
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Redirect Not Working as Expected in @tanstack/react-router v1.31.1 #1528
Comments
I am having the same issue |
Same here. The page stays empty unless manually refreshed. |
Facing the same issue. The page content does not load. The page has to be manually refreshed for the content to be loaded. |
Facing the ame issue, but only if there is two redirects in row. For example, if I have $lang in path param and all pages starts from $lang. So, if user open link with no path, first redirect is to /$lang and than in $lang/_authorised to $lang/login. I have already fixed it by changin logic to redirect to /$lang/login on start, if there is no $lang param, but also user is not authorised |
does this still occur with v 1.31.2? |
Well, it navigates now but the location (URL) does not change. |
Im getting the opposite, still same problem. If I have Will triple check to see if I had any cached versions of my project. |
For me 1.31.2 fixed redirect when there is only one redirect in row, but if there are two or more redirects in row it does not work. I fixed it in my code, so I do not do two redirects in row for now, but sometimes it can happen, so, I think it should work, doesn't matter is it 1 or 10 redirects in row |
I recently updated to version 1.31.3 and noticed that the router.invalidate() issue seems to be resolved. However, the "throw redirect" functionality is still problematic. Here's what I encountered with this new update:
Here's the code I use for redirect checks: //Filename: _public-layout.tsx
...
export const Route = createFileRoute('/_public-layout')({
beforeLoad({ context }) {
authenticated(context.auth);
},
component: PublicLayout,
}); //Filename: _layout.tsx
...
export const Route is createFileRoute('/_layout')({
beforeLoad({ context, location }) {
unauthenticated(context.auth, location);
},
component: AuthLayout,
}); //Filename: authUtils.ts
...
export function unauthenticated(auth: AuthContextType, location: ParsedLocation) {
if (!auth.isAuthenticated) {
throw redirect({
to: appConfig.LOGIN_PAGE,
search: {
redirect: location.href
}
})
}
}
export function authenticated(auth: AuthContextType) {
if (auth.isAuthenticated) {
throw redirect({
to: appConfig.DEFAULT_PAGE
})
}
} |
While waiting for the fix, downgrade to |
I'm facing the same issue, I've also updated to 1.31.3 but no luck |
Left a comment in another thread with reproducible demo of the bug |
Describe the bug
In @tanstack/react-router version 1.31.1, when i using the
beforeLoad
method to perform a redirect, the URL changes but the page does not navigate to the new destination. Instead, it stays on the same page. This issue occurs when trying to redirect based on authentication state in my code as you can see below.`
import PublicLayout from '@/layouts/PublicLayout'
import { authenticated } from '@/lib/authUtils'
import { createFileRoute } from '@tanstack/react-router'
export const Route = createFileRoute('/_public-layout')({
beforeLoad({ context }) {
authenticated(context.auth)
},
component: PublicLayout
})
...
export function authenticated(auth: AuthContextType) {
if (auth.isAuthenticated) {
throw redirect({
to: appConfig.DEFAULT_PAGE
})
}
}
`
Your Example Website or App
The issue can be reproduced in any basic authentication flow implemented with @tanstack/react-router where conditional redirects are used to handle authenticated and unauthenticated states. Unfortunately, I cannot provide a live URL as this is running locally, but I can provide a sample repository if required.
Steps to Reproduce the Bug or Issue
beforeLoad
method.redirect
function to redirect unauthenticated users to a login page.Expected behavior
When a user is not authenticated, and the
redirect
function is called withinbeforeLoad
, I expect the application to navigate to the specified login page and not just change the URL. Same is for the scenario otherwise.Screenshots or Videos
No response
Platform
Additional context
No response
The text was updated successfully, but these errors were encountered: