通过重写机制,`/fr/does-not-exist` 会被作为 `/does-not-exist` 进行匹配,且 `getLocale()` 依然返回 `fr`,因此第 7 步中的根 `notFoundComponent` 会以法语渲染。通配路由(catch-all route)确保深层路径也能正确进入 404 页面。将页面标记为 `noindex`:React 19 会将 `` 自动提升到 `` 中。
```tsx fileName="src/components/NotFound.tsx"
import { Link } from "@tanstack/react-router";
import { m } from "@/paraglide/messages";
export const NotFound = () => (
{m.not_found_title()}
{m.not_found_back_home()}
);
```
```tsx fileName="src/routes/$.tsx"
import { createFileRoute, notFound } from "@tanstack/react-router";
export const Route = createFileRoute("/$")({
beforeLoad: () => {
throw notFound();
},
});
```