T
TanStack2y ago
puzzled-coral

beforeLoad() property on createLazyFileRoute?

I’m trying to modify context (for breadcrumbs) and noticed that createLazyFileRoute doesn’t expose a beforeLoad property like createFileRoute does. Is there a way to modify context in a lazy loaded route?
4 Replies
puzzled-coral
puzzled-coralOP2y ago
It looks like this was a misunderstanding on my part and that for code-splitting you may require two separate routes: one that's lazy with the component and one that's not (with beforeLoad).
graceful-blue
graceful-blue2y ago
This is to do with the Critical Route Configuration and the Non-critical Configuration. https://tanstack.com/router/latest/docs/framework/react/guide/code-splitting#how-does-tanstack-router-split-code
graceful-blue
graceful-blue2y ago
Or you could try out the experimental.enableCodeSplitting flag if you want to test drive it. https://github.com/TanStack/router/blob/b43f5464ebff6c88f229c19c65dac4d205e6a810/examples/react/basic-file-based/vite.config.js#L12 That way you don't need to have a separate .lazy.tsx route.
GitHub
router/examples/react/basic-file-based/vite.config.js at b43f5464eb...
🤖 Fully typesafe Router for React (and friends) w/ built-in caching, 1st class search-param APIs, client-side cache integration and isomorphic rendering. - TanStack/router
puzzled-coral
puzzled-coralOP2y ago
Interesting, I'll definitely take a look, thanks!

Did you find this page helpful?