refactor: update sitemap and navigation with locale-specific pathname functions
- Rename `getPathname` to `getLocalePathname` in navigation module - Update sitemap generation to use new locale-specific pathname function - Add root path to routing pathnames configuration - Improve type safety and internationalization consistency in routing
This commit is contained in:
parent
675323fb69
commit
d6a230a2dc
@ -6,5 +6,5 @@ import { routing } from "./routing";
|
||||
*
|
||||
* https://next-intl.dev/docs/routing/navigation
|
||||
*/
|
||||
export const { Link: LocaleLink, getPathname, redirect, usePathname, useRouter } =
|
||||
export const { Link: LocaleLink, getPathname: getLocalePathname, redirect, usePathname, useRouter } =
|
||||
createNavigation(routing);
|
||||
|
@ -35,6 +35,9 @@ export const routing = defineRouting({
|
||||
// https://next-intl.dev/docs/routing#pathnames
|
||||
// whenever use pathname in LocaleLink, you need to add it here
|
||||
pathnames: {
|
||||
// used in sietmap.ts
|
||||
"/": "/",
|
||||
// used in blog pages
|
||||
"/blog/[...slug]": "/blog/[...slug]",
|
||||
"/blog/category/[slug]": "/blog/category/[slug]",
|
||||
},
|
||||
|
@ -1,13 +1,13 @@
|
||||
import { MetadataRoute } from 'next';
|
||||
import { routing, Locale } from '@/i18n/routing';
|
||||
import { getPathname } from '@/i18n/navigation';
|
||||
import { getLocalePathname } from '@/i18n/navigation';
|
||||
import { siteConfig } from './config/site';
|
||||
|
||||
export default function sitemap(): MetadataRoute.Sitemap {
|
||||
return [...getEntries('/')];
|
||||
}
|
||||
|
||||
type Href = Parameters<typeof getPathname>[0]['href'];
|
||||
type Href = Parameters<typeof getLocalePathname>[0]['href'];
|
||||
|
||||
/**
|
||||
* https://github.com/amannn/next-intl/blob/main/examples/example-app-router/src/app/sitemap.ts
|
||||
@ -24,6 +24,6 @@ function getEntries(href: Href) {
|
||||
}
|
||||
|
||||
function getUrl(href: Href, locale: Locale) {
|
||||
const pathname = getPathname({ locale, href });
|
||||
const pathname = getLocalePathname({ locale, href });
|
||||
return siteConfig.url + pathname;
|
||||
}
|
Loading…
Reference in New Issue
Block a user