TanStackT
TanStack2y ago
2 replies
full-green

redirect in beforeLoad/loader causes infinite loop

I have a layout _authed,
export const Route = createFileRoute("/_authed")({
  component: LayoutComponent,
  beforeLoad: async ({ context: { queryClient } }) => {
    const avatars = await queryClient.fetchQuery(avatarListQueryOptions);

    if (!avatars.length) {
      throw redirect({ to: "/avaturn" });
    }
  },
});


No idea why it causes an infinite loop. For now, I moved the logic to a child route, instead of the layout.
Was this page helpful?