Emit document title on error pages (404/500) per TZ 4.1.21
Previously the 404/500 React ErrorPage set the page content but not document.title, so the browser tab showed the URL path instead of a localized title. Added <title> element + imperative document.title assignment (pattern from SeoHead.tsx) so both SSR and client set the tab title to "<code> — <localized-title>", e.g. "404 — Страница не найдена".
This commit is contained in:
@@ -120,9 +120,19 @@ export function ErrorPage({ code }: ErrorPageProps): JSX.Element {
|
||||
const support = translations?.support ?? "Поддержка";
|
||||
const refresh = translations?.refresh ?? (config.refreshKey ? "Обновить страницу" : undefined);
|
||||
const displayCode = code ?? "?";
|
||||
const documentTitle = `${displayCode} — ${title}`;
|
||||
|
||||
// React 18 doesn't hoist <title> inside body to document.head, so set
|
||||
// document.title imperatively on the client once translations resolve.
|
||||
useEffect(() => {
|
||||
if (typeof document !== "undefined" && translations) {
|
||||
document.title = documentTitle;
|
||||
}
|
||||
}, [documentTitle, translations]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<title>{documentTitle}</title>
|
||||
{/* noindex: error pages must not be indexed (TZ §4.1.21) */}
|
||||
<meta name="robots" content="noindex,nofollow" />
|
||||
<div className="error-page" data-testid={`error-page-${code ?? "unknown"}`}>
|
||||
|
||||
Reference in New Issue
Block a user