Skip to content
masterclass Buddy

TanStack · Pipe

beforeLoad

Use a route's beforeLoad function to check authentication before the route and its children load. Throw redirect() to send unauthenticated users to login, while private server data still needs its own authorization.

Last updated

Syntax

beforeLoad: ({ context, location }) => { if (!context.auth.isAuthenticated) throw redirect({ to: '/login' }) }

In-depth API docs are only for subscribers: parameters, examples, common mistakes and interview practice.

Subscribe
  • redirect()
  • route.loader
  • Pathless Route
  • Layout Route
  • Authenticated Routes
  • Authentication Server Primitives

Source: Authenticated Routes | TanStack Router Docs. Checked 2026-11-03.