TanStackT
TanStack2y ago
2 replies
hurt-tomato

TanStack Router Docs Wrong? - Auth Example

Is it possible this is a typo?

https://tanstack.com/router/latest/docs/framework/react/guide/authenticated-routes

Under redirecting
// src/routes/_authenticated.tsx
export const Route = createFileRoute('/_authenticated')({
beforeLoad: async ({ location }) => {
if (!isAuthenticated()) {
throw redirect({
to: '/login',
search: {
// Use the current location to power a redirect after login
// (Do not use router.state.resolvedLocation as it can
// potentially lag behind the actual current location)
redirect: location.href,
},
})
}
},
})

Though if you look at redirect in tanstack router
export type Redirect<TRouter extends AnyRouter = RegisteredRouter, TFrom extends RoutePaths<TRouter['routeTree']> = '/', TTo extends string = '', TMaskFrom extends RoutePaths<TRouter['routeTree']> = TFrom, TMaskTo extends string = ''> = {
/
* @deprecated Use statusCode instead
/
href?: string;
code?: number;
statusCode?: number;
throw?: any;
headers?: HeadersInit;
} & NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>;

Shouldn't it be href and not to?
image.png
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
Authenticated Routes | TanStack Router React Docs
Was this page helpful?