-
-
Notifications
You must be signed in to change notification settings - Fork 233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Localized pathnames don't work with Dynamic params #643
Comments
Hey, you probably want to check "How can I change the locale for the current page?" in the Hope this helps! |
OK, thank you, I've finally replaced it:
with this:
Thanks for the help |
Looks good! 🙌 |
Hello guys, I've the same issue as you. I've implemented a LanguageSwitcher on the Header which change the website language. When I'm on the path /en/shop/category-x/product-y (solved by a DynamicPath pattern) and I switch from english to another language I got the error: "Insufficient params provided for localized pathname" and nothing happens on the page. If I console log the pathname returned by usePathname hook I got the folder pattern /shop/[...slug] as excpected. The solution proposed by @Benlasc is hardcoded for that product how can I solve this in order to handle correctly all the dynamic routes inside the Website? |
"use client";
import { useParams } from "next/navigation";
import { usePathname, useRouter } from "@/navigation";
export default function LanguageSwitcher(props: { locales: string[] }) {
const router = useRouter();
const pathname = usePathname();
const params = useParams();
const changeLanguage = (lang: string) => {
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
router.push({ pathname, params: params as any }, { locale: lang });
};
return (
<div>
{props.locales.map((lang) => (
<button key={lang} onClick={() => changeLanguage(lang)}>
{lang.toUpperCase()}
</button>
))}
</div>
);
} I encountered a similar problem. It turned out that you can get the current parameters for pathname using the |
Thanks, you're a boss. |
How can we achieve this using a Link component? |
For anyone encountering an error 🟥 Wrong:
🟩 Correct:
|
For those who came across the same issue using next-intl Link component, I think the path param mechanism is sort of bugged (using next-intl Compiles but doesn't work, throws
Works:
|
Description
Hello, I used the github code: next-intl/examples/example-app-router to show you my problem (see the codesandbox link below).
In the src/config.ts file I defined a url with a dynamic parameter id :
/customer/[id]': {
en: '/customer/[id]',
de: '/customer-de/[id]'.
When the user is on the /en/customer/100 url and chooses the 'de' locale, I'd like the url to become /de/customer-de/100.
The problem is that I have an error on the line "router.replace(pathname, {locale: nextLocale})" in the "LocaleSwitcherSelect.tsx" file:
Error: Insufficient params provided for localized pathname.
Template: /customer-de/[id]
Params: undefined
Is this a bug that needs to be fixed or an error on my part?
Thank you.
Mandatory reproduction URL (CodeSandbox or GitHub repository)
https://codesandbox.io/p/sandbox/next-intl-bug-template-app-forked-yy3xtl?file=%2Fsrc%2Fconfig.ts%3A12%2C24
Reproduction description
Steps to reproduce:
Error: Insufficient params provided for localized pathname.
Template: /customer-de/[id]
Params: undefined
Expected behaviour
When the user is on the /en/customer/100 url and chooses the 'de' locale, I'd like the url to become /de/customer-de/100.
The text was updated successfully, but these errors were encountered: