Skip to content

Allow titleTemplate in middleware's headDefaults #796

Closed

Description

@karthickeyan-dev

Version

void 1.8.0, and main at a2eecec

Problem

titleTemplate can only be set once, for the whole site, in void.config.ts.

resolveHead() in src/pages/head.ts reads the template only from the config layer:

const template = configHead?.titleTemplate;

headDefaults is typed HeadDescriptor, which has no titleTemplate, and a layout can't set head. So nothing can give one section of the site its own template:

// middleware/admin.ts
export default defineMiddleware(async (c, next) => {
  if (c.req.path.startsWith('/admin')) {
    c.set('headDefaults', { ...c.get('headDefaults'), titleTemplate: '%s | Admin' });
  }
  await next();
});

This doesn't type check, and if it's cast the template is ignored. Admin tabs read "Users | My Site" like every other page, so they can't be told apart from the app's own tabs. Today each admin page has to build Users | Admin by hand, and leave out the config's titleTemplate, or the site name would be added too.

Proposal

Let headDefaults take titleTemplate, and have resolveHead() use the middleware's template before the config's:

const template = middlewareHead?.titleTemplate ?? configHead?.titleTemplate;

Sites that don't set it in middleware see no change.

I'm happy to open a PR for this.

Prior art

  • Next.js: title.template in a layout's metadata applies to every page below it.
  • TanStack Router: head() on a layout route can set the title for its children.

Activity

  1. added a commit that references this issue on Nov 13, 2026
    4bdd425
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions