Best way to restrict i18n route params?
Hey, I'm exploring to migrate from Next.js :)
How do I restrict my
$lang
route param to only allow valid values of the languages I support? Right now I tried something like this but I would have to maintain a list of reserved paths.
Also favicon.ico
etc trigger this param which makes this error prone and annoying to maintain 🤔
6 Replies
ambitious-aqua•6mo ago
hi there!
what kind of "reserved" paths do you mean here?
any static file/folder in the public dir should not reach the route
optimistic-goldOP•6mo ago
Oh yes, I had the public dir in the wrong location. Yesterday I often got some $lang params with
_build
but I can't reproduce it now.
Thanks for your fast response 🙏
@Manuel Schiller I got the playback. If any error is thrown and the error overlay is displayed, then the Error: Invalid language: _build
is thrown. Somehow the route is matched and the param is trying to get parsed.ambitious-aqua•6mo ago
what kind of error is thrown here?
and where?
the initial one I mean that is causing this
optimistic-goldOP•6mo ago
For example:
[vite] Internal server error: /PATH_TO_PROJECT/app/components/theme.tsx: Export 'useTheme' is not defined.
But also importing a package that is not installedambitious-aqua•6mo ago
well in such cases vite dev server is totally borked, so I wouldn't expect it to work properly
so this is not a normal operation mode
or an error that could be properly handled
optimistic-goldOP•6mo ago
Okay, I don't mind it. I just got confused because of the
favicon.ico
error so I thought it's the same.
Thanks again :)