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 摘要。