1

In next.js i18n redirect only works from main page "/"

If cookie NEXT_LOCALE is set to "fr" it will redirect from "/" to "/fr" but it won't redirect from "/about" to "/fr/about"

const router = useRouter();
const { pathname, asPath, query } = router;

const handleSelectLanugage = (code) => {
 document.cookie = `NEXT_LOCALE=${code};path=/`;
 router.push({ pathname, query }, asPath, { locale: code });
};

next.config.js

  i18n: {
    locales: ["en", "pl", "fr"],
    defaultLocale: "en",
  },

What should i do to make it work for every page?

  • Try setting a high `max-age` value on the cookie. See [Storing selected language option in cookie/localSession](https://stackoverflow.com/questions/66618637/storing-selected-language-option-in-cookie-localsession). – juliomalves Sep 14 '22 at 20:53

0 Answers0