Repository navigation
How to type the head function of the options parameter of the function returned by createRootRouteWithContext #5651
Unanswered
HcySunYang
asked this question in
Q&A
Replies: 1 comment
|
The options parameter is optional, so its type includes This compiles on the current Router version, including passing the extracted function back into the route: import { createRootRouteWithContext, type Register } from '@tanstack/react-router'
interface RouterContext { title: string }
const makeRoot = createRootRouteWithContext<RouterContext>()
type Options = NonNullable<Parameters<typeof makeRoot<Register>>[0]>
type HeadCreatorType = NonNullable<Options['head']>
const headCreator: HeadCreatorType = ({ match }) => ({
meta: [{ title: match.context.title }],
})
const rootRoute = makeRoot({ head: headCreator, component: () => null })
Checked with AI-assisted; locally type-checked. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Hi team, I am working on a SSR project, I found that I can't extract the
headfunction outside due to there is no way to type it. I was trying to type it like below:As you can see, the ts compiler says that
Property 'head' does not exist on type. How can I achieve that? thanksAll reactions