hozana / next-translate-routes

Flexible and translated routes for Next.js without custom server
MIT License
115 stars 30 forks source link

1.9.0-3 - navigation to wrong translation reloads the app #46

Closed kruzliak-juraj closed 2 years ago

kruzliak-juraj commented 2 years ago

Since I can not use 1.8.0 due to this issue I am using the 1.9.0-3

I have this structure:

/author
--[slug].tsx
--_routes.json
[...catchAll].tsx
index.tsx

in routes.json is defined:

{
  "/": {
    "cz": "autori",
    "en": "authors"
  }
}

The issue

When navigating with useRouter or Link from next-translate-routes/link and trying to navigate to the 'incorrectly' translated path the part of path that should be translated stays the same

router.push('cz/author/name-of-author', 'cz/author/name-of-author', { locale: 'cz' })

or

<Link href={'cz/author/name-of-author'} locale={ 'cz' } >

Both route to __domain__/cz/author/name-of-author instead of __domain__/cz/autori/name-of-author. Link also generates the URLs with wrong translation in html.

On full reload, the URLs is properly translated.

cvolant commented 2 years ago

Hi @kruzliak-juraj, thanks for the report. I reworked this part before publishing 1.9.0, and it should work now. I tried to be more compliant with Next docs, and the behaviour may surprise you sometimes: if you want the locale in the href to be taken into account, you need to set locale to false. Please reopen the issue if you still have bugs.