Skip to content

Commit

Permalink
Merge pull request #1845 from gettakaro/fix/navigation-redirect
Browse files Browse the repository at this point in the history
fix(web-main) navigate back resulting in redirect triggering again
  • Loading branch information
emielvanseveren authored Dec 18, 2024
2 parents 8f29359 + afe7c1c commit fa188c2
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/web-main/src/routes/_auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const Route = createFileRoute('/_auth')({
const session = await context.auth.getSession();
if (!session) {
const redirectPath = location.pathname === '/login' ? '/' : location.pathname;
throw redirect({ to: '/login', search: { redirect: redirectPath } });
throw redirect({ to: '/login', search: { redirect: redirectPath }, replace: true });
}
},
loader: async ({ context }) => {
Expand Down
6 changes: 5 additions & 1 deletion packages/web-main/src/routes/_auth/_global.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ export const Route = createFileRoute('/_auth/_global')({
if (location.pathname == '/' && !canManageGameServers) {
const gameservers = await context.queryClient.ensureQueryData(gameServersQueryOptions());
if (gameservers.data.length > 0) {
throw redirect({ to: '/gameserver/$gameServerId/shop', params: { gameServerId: gameservers.data[0].id } });
throw redirect({
to: '/gameserver/$gameServerId/shop',
params: { gameServerId: gameservers.data[0].id },
replace: true,
});
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion packages/web-main/src/routes/_auth/_global/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const Route = createFileRoute('/_auth/_global/')({
beforeLoad: async ({ context }) => {
const session = await context.queryClient.ensureQueryData(userMeQueryOptions());
if (hasPermission(session, [PERMISSIONS.ReadEvents])) {
throw redirect({ to: '/dashboard' });
throw redirect({ to: '/dashboard', replace: true });
}

/* if user has no permissions at all, so can't see any page, redirect to forbidden */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createFileRoute } from '@tanstack/react-router';
import { createFileRoute, redirect } from '@tanstack/react-router';

export const Route = createFileRoute('/_auth/_global/player/$playerId/')({
beforeLoad: ({ navigate, params }) => {
navigate({ to: '/player/$playerId/info', params: { playerId: params.playerId } });
beforeLoad: ({ params }) => {
throw redirect({ to: '/player/$playerId/info', params: { playerId: params.playerId }, replace: true });
},
});
6 changes: 3 additions & 3 deletions packages/web-main/src/routes/_auth/_global/settings/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createFileRoute } from '@tanstack/react-router';
import { createFileRoute, redirect } from '@tanstack/react-router';

export const Route = createFileRoute('/_auth/_global/settings/')({
beforeLoad: ({ navigate }) => {
navigate({ to: '/settings/gameservers' });
beforeLoad: () => {
throw redirect({ to: '/settings/gameservers', replace: true });
},
});

0 comments on commit fa188c2

Please sign in to comment.