TanStackT
TanStack2y ago
4 replies
colourful-plum

beforeLoad with file based routing?

Hi, I need a beforeLoad and i'm using file based routing but the docs only mention how to do this when you're defining the rotes through code as far as I can see. Can someone point to me on how to add a beforeLoad? My use case is that I want a beforeLoad in my root index.component.tsx to check if i'm authenticated and redirect to /login if not.

I'm checking the docs here: https://tanstack.com/router/latest/docs/framework/react/guide/authenticated-routes
Authentication is an extremely common requirement for web applications. In this guide, we'll walk through how to use TanStack Router to build protected routes, and how to redirect users to login if they try to access them.

The route.beforeLoad Option
Was this page helpful?