-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Open
Description
Feature Request
Description
The head route option currently only accepts a function:
export const Route = createFileRoute('/')({
head: () => ({
meta: [{ title: 'My App' }, { charSet: 'UTF-8' }],
links: [{ rel: 'icon', href: '/favicon.ico' }],
}),
})Many routes have static head content that doesn't depend on route context (params, loaderData, etc.). For these cases, the function wrapper is unnecessary boilerplate. It would be nice to also accept a const/static object:
export const Route = createFileRoute('/')({
head: {
meta: [{ title: 'My App' }, { charSet: 'UTF-8' }],
links: [{ rel: 'icon', href: '/favicon.ico' }],
},
})Precedent
The loader option already accepts both a function (RouteLoaderFn) and an object (RouteLoaderObject), so this pattern has precedent in the codebase.
Scope
This would only apply to head. The standalone scripts option has legitimate dynamic use cases (e.g., JSON-LD from loaderData), and headers could follow later if desired.
Implementation
The change is minimal:
- Type: Make
heada union of the existing function type and the static object type (packages/router-core/src/route.ts) - Runtime: Add a
typeof === 'function'check before callinghead(packages/router-core/src/load-matches.ts)
I'm happy to submit a PR for this.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels