Important
If you are using file-based routing, it's recommended to use the createLazyFileRoute function instead.
The lazyRouteComponent function can be used to create a one-off code-split route component that can be preloaded using a component.preload() method.
The lazyRouteComponent function accepts two arguments:
import { lazyRouteComponent } from '@tanstack/react-router'
const route = createRoute({
path: '/posts/$postId',
component: lazyRouteComponent(() => import('./Post')), // default export
})
// or
const route = createRoute({
path: '/posts/$postId',
component: lazyRouteComponent(
() => import('./Post'),
'PostByIdPageComponent', // named export
),
})
import { lazyRouteComponent } from '@tanstack/react-router'
const route = createRoute({
path: '/posts/$postId',
component: lazyRouteComponent(() => import('./Post')), // default export
})
// or
const route = createRoute({
path: '/posts/$postId',
component: lazyRouteComponent(
() => import('./Post'),
'PostByIdPageComponent', // named export
),
})
Your weekly dose of JavaScript news. Delivered every Monday to over 100,000 devs, for free.