The createLazyFileRoute function is used for creating a partial file-based route route instance that is lazily loaded when matched. This route instance can only be used to configure the non-critical properties of the route, such as component, pendingComponent, errorComponent, and the notFoundComponent.
The createLazyFileRoute function accepts a single argument of type string that represents the path of the file that the route will be generated from.
A new function that accepts a single argument of partial of the type RouteOptions that will be used to configure the file Route instance.
Pick<
RouteOptions,
'component' | 'pendingComponent' | 'errorComponent' | 'notFoundComponent'
>
Pick<
RouteOptions,
'component' | 'pendingComponent' | 'errorComponent' | 'notFoundComponent'
>
⚠️ Note: For tsr generate and tsr watch to work properly, the file route instance must be exported from the file using the Route identifier.
import { createLazyFileRoute } from '@tanstack/react-router'
export const Route = createLazyFileRoute('/')({
component: IndexComponent,
})
function IndexComponent() {
const data = Route.useLoaderData()
return <div>{data}</div>
}
import { createLazyFileRoute } from '@tanstack/react-router'
export const Route = createLazyFileRoute('/')({
component: IndexComponent,
})
function IndexComponent() {
const data = Route.useLoaderData()
return <div>{data}</div>
}
Your weekly dose of JavaScript news. Delivered every Monday to over 100,000 devs, for free.