i18nexus / next-i18n-router

Next.js App Router internationalized routing and locale detection.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Doesn't work properly when cookies are not accessible

mikhailChelbaev opened this issue · comments

In situations where cookies are not accessible, such as when using Incognito Mode, the router retrieves a value from the header or returns a default locale. So, the app may not function correctly when using noPrefix or when prefixDefault=false. A potential fix to this issue could be to introduce an option to set a locale value in the session storage.

I just ran this repo's example project in Incognito Mode and it works as expected. Incognito Mode allows cookie usage, but it clears the cookies after closing the window. Similarly, it clears local storage and session storage when closing the window. This is expected.

If you truly do not want to use cookies at all with next-i18n-router, that is currently possible. You just need to do the following:

  1. Set serverSetCookie to "never"
  2. Prefix all hrefs on your links with the current locale. For example:
<Link href={`/${locale}/about-us`}>About Us</Link>

If using noPrefix, then you have to use cookies. How else would the server know what language to use? The server needs you to send it the language either via cookie or via pathname. Since we can't use pathname with noPrefix, then we have to use a cookie.

Let me know if this makes sense.

Ok, it makes sense, thank you!