Let `_not-found` and `_error` set their title, and apply `titleTemplate` to the default one

未关闭
#825 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
react, typescript
领域
full-stack

调研方向

Start with renderPageFailure() and resolveHead(), where the fallback title is added after the head is resolved, so the template is never applied to it. Check how _not-found and _error are rendered, and whether the second proposal (a head export for error pages) is needed or whether applying the template is enough. Done means a 404 page's <title> reads Not Found | My App when titleTemplate is set, and the existing tests still pass. Confirm the design direction with a maintainer before adding a new export.

由索引模型根据 Issue 内容生成。

描述

Version

void 1.9.0

Problem

With head: { titleTemplate: '%s | My App' } in void.config.ts, every page's tab gets the app name, except the error pages:

Path Status <title>
/ 200 Home | My App
/about 200 About | My App
/no-such-page 404 Not Found

renderPageFailure() resolves the head with no page title, so resolveHead() never applies the template. It then adds its own title after that step:

title: head?.title ?? (status === 404 ? 'Not Found' : 'Internal Server Error')

_not-found and _error can't change this either. They can't have a .server.ts, so they have no head, and a headDefaults.title set in middleware would reach every page that sets no title of its own, not just the error pages. So the error pages can't say "Page not found" to match their heading, and they're the only tabs without the app name.

Proposal
  1. Apply the template to the default title, by passing it through resolveHead() as the page title: Not Found | My App. That's a small change, and it makes these pages match every other page without any code in the app.

  2. Let error pages set their title. For example, a head export from _not-found and _error, taking the error they render:

    // pages/_not-found.tsx
    export const head = { title: 'Page not found' };
    
    // pages/_error.tsx
    export const head = (error: PageError) => ({
      title: error.status === 404 ? 'Page not found' : 'Something went wrong',
    });
    
Prior art
  • Next.js: not-found.tsx can export metadata, and the root layout's title.template applies to it.
  • Nuxt: error.vue calls useHead(), and the app's titleTemplate applies.
  • SvelteKit: +error.svelte sets its title with <svelte:head>.
主要语言
TypeScript
星标
684
派生
83
平均合并
15 小时 22 分钟
30 天内合并 PR
219

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

voidzero-dev/void 的其他 Issue

查看 voidzero-dev/void 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。