Redirect in React

From the TanStack Router cheat sheet · Navigation & Links · verified Jul 2026

Redirect

Redirect from loaders and actions

typescript
import { redirect } from '@tanstack/react-router'

export const Route = createFileRoute('/dashboard')({
  beforeLoad: ({ context }) => {
    if (!context.auth.isAuthenticated) {
      throw redirect({ to: '/login' })
    }
  },
})
💡 throw redirect() to exit execution
⚡ Use in beforeLoad for auth guards
🔍 Can redirect from loader if data missing
🎯 Pass search.redirect for return URLs
redirectauthguards

Continue with TanStack Router

Save the full cheat sheet or work through every related task.

More React tasks

Back to the full TanStack Router cheat sheet