This is my what next-intl talk about how to implement dynamic urls for dynamic pages:
import {
createLocalizedPathnamesNavigation,
Pathnames
} from 'next-intl/navigation';
export const locales = ['en', 'de'] as const;
export const localePrefix = 'always'; // Default
// The `pathnames` object holds pairs of internal
// and external paths, separated by locale.
export const pathnames = {
// If all locales use the same pathname, a
// single external path can be provided.
'/': '/',
'/blog': '/blog',
// If locales use different paths, you can
// specify each external path per locale.
'/about': {
en: '/about',
de: '/ueber-uns'
},
// Dynamic params are supported via square brackets
'/news/[articleSlug]-[articleId]': {
en: '/news/[articleSlug]-[articleId]',
de: '/neuigkeiten/[articleSlug]-[articleId]'
},
// Also (optional) catch-all segments are supported
'/categories/[...slug]': {
en: '/categories/[...slug]',
de: '/kategorien/[...slug]'
}
} satisfies Pathnames<typeof locales>;
export const {Link, redirect, usePathname, useRouter, getPathname} =
createLocalizedPathnamesNavigation({locales, localePrefix, pathnames});
How can I pass articleSlug
, when the slug I get from MongoDB, with both the Vietnamese and English page having one URL?
New contributor
Thanh Giang Le is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1