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?Authenticated Routes | TanStack Router React Docs
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

1 Reply
conscious-sapphire•14mo ago
If you mean whether you should be using
href
instead of to
on the top-level of the redirect
helper, then no.
Its meant to be: throw redirect({ to: '/destination' })
What you get on the location
property is a subset of what you get out of location in the History API.