hozana / next-translate-routes

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

fileUrlToUrl breaks on 404 #60

Closed okkindel closed 1 year ago

okkindel commented 1 year ago

image

fileUrlToUrl function should be protected for nonexistent paths.

cvolant commented 1 year ago

I hesitated about it... and decided to throw and to use it in a try-catch. Maybe it was a wrong choice. That is right that at least the function docs should mention it, and it does not yet. Why do you think that this function should not throw?

cvolant commented 1 year ago

So, I decided to throw as the default behavior, but starting from 1.9.2, you can prevent that using a 3rd argument:

const translatedUrl = fileUrlToUrl(fileUrl, locale, { throwOnError: false })

It will return undefined instead of throwing an error.