#Why context auth doesn't work if the router is lazy?

3 messages · Page 1 of 1 (latest)

raw jetty
#

I want to put router lazy, but if a put the context it's not gonna work

import { createLazyFileRoute, redirect } from '@tanstack/react-router'
import Home from "@pages/home"


export const Route = createLazyFileRoute('/')({
    beforeLoad: ({ context, location }) => {
      if (!context.auth.isAuthenticated) {
        console.log("context auth: ",context.auth.isAuthenticated)
        throw redirect({
          to: '/login',
          search: {
            redirect: location.href,
          },
        })
      }
    },
    component: Home
  })
teal coral
#

You need to have both index.tsx for the critical configuration and index.lazy.tsx for the component code splitting.