hozana / next-translate-routes

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

Incorrect translation of external links #55

Open simonhenke opened 1 year ago

simonhenke commented 1 year ago

Some version between 1.8.0-1 and 1.9.1 now causes external links to be translated incorrectly: I'm passing a href like https://www.dhl.com/de-de/home/tracking/tracking-express.html and the lib parses it to /de-de/home/tracking/tracking-express.html

My current workaround is something like const Link = href.toString().startsWith("http") ? NextLink : NextTranslateRoutesLink; which I then render in a custom component.

But it would be better if the next-translate-routes wouldn't translate external links.

cvolant commented 1 year ago

Yes, it should not. Seems like a bug the tests did not catch.

ctrichereau commented 1 year ago

Hey guys !

We have some similar issues with our project. Our config :

We pass this url as href: https://www.domain.com/fr/this-website-part and the lib parse it to this url : https://www.domain.com/fr/frhttps:/www.domain.com/this-website-part/

We use the tips from @simonhenke for prevent this problem and it's working well.

Thanks in advance !

cvolant commented 1 year ago

Until now, next-translate-routes tries to match any url pathname with a local page. If it fails to do so, it returns use the raw url as is. The problem is that an external url pathname can match a local page, especially if you use match all pages.

So we need to add a domain check, but it is not that easy because there could be several local domain depending on the locale. Cf. https://nextjs.org/docs/advanced-features/i18n-routing#domain-routing

So we need to fix this issue first.

ctrichereau commented 1 year ago

Thanks @cvolant for the answer. We will wait for updates