T
TanStack15mo ago
xenogeneic-maroon

How can I use "loader" with "createLazyFileRoute"?

I have this lazy route and I'm not sure how to use the loader function:
export const Route = createLazyFileRoute("/(customers)/customers")({
loader: async ({ context: { queryClient } }) => {
return queryClient.ensureQueryData(customersQueryOptions())
},
errorComponent: StateError,
notFoundComponent: StateNotFound,
component: () => {},
})
export const Route = createLazyFileRoute("/(customers)/customers")({
loader: async ({ context: { queryClient } }) => {
return queryClient.ensureQueryData(customersQueryOptions())
},
errorComponent: StateError,
notFoundComponent: StateNotFound,
component: () => {},
})
does anybody knows how to do it?
2 Replies
conscious-sapphire
conscious-sapphire15mo ago
Check the docs, you need to make a non-lazy route for the loaders, besides your lazy route.
genetic-orange
genetic-orange11mo ago
please also check automatic codesplitting. no need really to use lazy routes manually

Did you find this page helpful?