-
Hi folks, I'm trying to use next-intl in server components and I have a navigation button to change the locale. As docs suggested, I configured my navigation.ts as below: import {
createLocalizedPathnamesNavigation,
Pathnames,
} from "next-intl/navigation";
export const locales = ["en", "tr"] as const;
// 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.
"/": "/",
// If locales use different paths, you can
// specify each external path per locale.
"/about": {
en: "/about",
tr: "/hakkinda",
},
"/projects": {
en: "/projects",
tr: "/projeler",
},
// Dynamic params are supported via square brackets
"/projects/[...endpoint]": {
en: "/projects/[...endpoint]",
tr: "/projeler/[...endpoint]",
},
} satisfies Pathnames<typeof locales>;
export const { Link, redirect, usePathname, useRouter, getPathname } =
createLocalizedPathnamesNavigation({ locales, pathnames }); projects/[...endpoint] is a dynamic route that renders individual project page. I'm storing my projects data in a JSON file and it includes variables called endpoint to generate static pages. So, I tried to use these endpoint variables to generate params to change the locale as below. router.replace(
{
pathname,
// TypeScript will validate that only known `params` are used in combination
// with a given `pathname`. Since the two will always match for the current
// route, we can skip runtime checks.
params: {
endpoint: projects.map((project) => project.endpoint),
//array of these values
//Learnification, Turkish-Dictionary-using-TDK-API, Meme-Generator, Frontend-Mentor-Challenges, Turkish-Dictionary
},
},
{ locale: locale === "en" ? "tr" : "en" } // locale from useLocale() to change to the opposite lang
); I'm able to open the project pages as I couldn't figure out what's wrong with my code, any help will be appreciated! I believe you can easily inspect the code related to next-intl and see the live link in this PR |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
this part was wrong "/projects/[...endpoint]": {
en: "/projects/[...endpoint]",
tr: "/projeler/[...endpoint]",
}, it should've been like this: "/projects/[endpoint]": {
en: "/projects/[endpoint]",
tr: "/projeler/[endpoint]",
} |
Beta Was this translation helpful? Give feedback.
this part was wrong
it should've been like this: