Skip to content

feat: allow head route option to accept a static object #6949

@WolfieLeader

Description

@WolfieLeader

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 head a union of the existing function type and the static object type (packages/router-core/src/route.ts)
  • Runtime: Add a typeof === 'function' check before calling head (packages/router-core/src/load-matches.ts)

I'm happy to submit a PR for this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions