I am using Next.js version 14 and next-intl.
I am facing an issue with i18n routing.
The problem is that a page that has been visited once is being cached.
So, if the page has a fetch call, it doesn’t make a new fetch when re-entering the page.
I am also using middleware, but it doesn’t get executed when accessing a cached page.
Here are my current file setups:
// navigation.ts
import { createSharedPathnamesNavigation } from "next-intl/navigation";
export const locales = ["ko", "en"] as const;
export const localePrefix = "always";
export const { Link, redirect, usePathname, useRouter } =
createSharedPathnamesNavigation({ locales, localePrefix });
// i18n.ts
import { notFound } from "next/navigation";
import { getRequestConfig } from "next-intl/server";
export const locales = ["ko"] as const;
export default getRequestConfig(async ({ locale }) => {
if (!locales.includes(locale as any)) notFound();
return {
messages: (await import(`../messages/${locale}.json`)).default,
};
});
This is how I am using them.
When I used a useRouter
in nextjs (next/navigation) it work well