T
TanStack2y ago
unwilling-turquoise

How to pass the props.

How to pass the props using lazyComponent(()=>import("@/Example"))
3 Replies
fair-rose
fair-rose2y ago
You don't pass props in this instance. You use the RouteApi helper for this
const routeApi = new RouteApi({ id:"/your-route-here" })

const component = () => {
const context = routeApi.useRouteContext()
// ...
}
const routeApi = new RouteApi({ id:"/your-route-here" })

const component = () => {
const context = routeApi.useRouteContext()
// ...
}
unwilling-turquoise
unwilling-turquoiseOP2y ago
Thank you @Sean Cassiere @Sean Cassiere do you know how to get location.state value I pass through the navigation how to get it.
fair-rose
fair-rose2y ago
What do you mean by that? In Tanstack Router pretty much the only state is passed around is either a path parameter or search parameter. You could set some custom context based data in the beforeLoad function in your route definition.
const location = useRouterState({select: (s)=>s.location)}
const location = useRouterState({select: (s)=>s.location)}
Also check what comes out of here, but location.state probably won't be type-safe.

Did you find this page helpful?