23 lines
1.1 KiB
JavaScript
23 lines
1.1 KiB
JavaScript
'use client';
|
|
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
// '.js' is required: `next` has no package.json "exports", so NodeNext resolution
|
|
// (this plugin's tsconfig) can't find 'next/navigation' without the extension.
|
|
// Bundlers in the project resolve the same file either way.
|
|
import { usePathname } from 'next/navigation.js';
|
|
/**
|
|
* Shows the view matching the locale in the current URL (`/en/...` → `en`).
|
|
*
|
|
* Made for `not-found.tsx`, which receives no `params`: reading the locale with
|
|
* `headers()` there turns an SSG/ISR route dynamic ("Page changed from static
|
|
* to dynamic at runtime"). `usePathname()` is client-side and static-safe, and
|
|
* it also runs during SSR, so the HTML already contains the right language.
|
|
*/ export function LocaleView({ defaultLocale, views }) {
|
|
const pathname = usePathname() ?? '';
|
|
const segment = pathname.split('/').filter(Boolean)[0] ?? '';
|
|
const locale = segment in views ? segment : defaultLocale;
|
|
return /*#__PURE__*/ _jsx(_Fragment, {
|
|
children: views[locale] ?? views[defaultLocale] ?? null
|
|
});
|
|
}
|
|
|
|
//# sourceMappingURL=LocaleView.js.map
|