I implemented a next-intl for multi-language support. So my paths look like www.next.com/de or www.next.com/en
I'm using NextJS 14.
<NextLink href="/support-us">{t("About us")}</NextLink>
And when I want to navigate to for example /support-us it must navigate me to /en/support-us instead I get to /support-us so it throws an error.
NotFoundError: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node.
Here is my code.
middleware.ts
import createMiddleware from "next-intl/middleware";
import { locales } from "./i18n";
export default createMiddleware({
// A list of all locales that are supported
locales,
// Used when no locale matches
defaultLocale: "en",
});
export const config = {
// Match only internationalized pathnames
matcher: ["/", "/(en|it|de|nl|fr|sv|es|nb|pt|pl)/:path*"],
};
i18next
import { notFound } from "next/navigation";
import { getRequestConfig } from "next-intl/server";
interface Language {
symbol: string;
name: string;
}
export const supportedLanguages: Language[] = [
{ symbol: "EN", name: "English" },
{ symbol: "DE", name: "Deutsch" },
];
const languageSymbolsLowercase: string[] = supportedLanguages.map((lang) =>
lang.symbol.toLowerCase()
);
const initialLocales: string[] = [];
const combinedLocales: string[] = [
...initialLocales,
...languageSymbolsLowercase,
];
export const locales: string[] = combinedLocales;
export default getRequestConfig(async ({ locale }) => {
if (!locales.includes(locale)) notFound();
return {
messages: (await import(`../messages/${locale}.json`)).default,
};
});
At the end I had to add a
navigation fileas mentioned in the next-intl documentation in there it exports aLinkcomponent which solves the problem and navigates to/[locale]/support-usfor example
/en/support-ushere is mynavigationfileAnd use the
Linkexported in the navigation file