T
TanStack•11mo ago
protestant-coral

Can I add custom information to RouteOptions?

I'm using TanStack Router with file-based routing and I'd like to dynamically generate my menu from the route tree. In order to do this, I need to have some extra metadata for each route (i.e. title, sort, etc.). Is it possible to add some extra information when calling createFileRoute (or createLazyFileRoute) that I can then access from the route tree data from useRouter or similar? Something like this, perhaps?
export const Route = createFileRoute('/')({
component: Page,
meta: { //<-- This is what I want
title: "Home",
},
})
export const Route = createFileRoute('/')({
component: Page,
meta: { //<-- This is what I want
title: "Home",
},
})
I've looked all over and can't seem to find info dynamically generating the menu. Maybe I'm missing something or going about it the wrong way?
5 Replies
rare-sapphire
rare-sapphire•11mo ago
I would suggest to enable autoCodeSplitting and not use manual lazy
protestant-coral
protestant-coralOP•11mo ago
That was just an example that I happened to have on hand. Not really what I was asking about. 😅
rare-sapphire
rare-sapphire•11mo ago
oh sorry I thought the fact that lazy file route has only a subset of the options was the issue here
rare-sapphire
rare-sapphire•11mo ago
Static Route Data | TanStack Router React Docs
When creating routes, you can optionally specify a staticData property in the route's options. This object can literally contain anything you want as long as it's synchronously available when you crea...
protestant-coral
protestant-coralOP•11mo ago
Ah, that looks perfect. Thank you!

Did you find this page helpful?