Closed bliitzkrieg closed 7 years ago
I think I found a solution. If I put a ? on :lang it seems to work as I'd like.
routes.add('page', '/:lang?/page/:slug');
That's the right way! More info on possible route patterns can be found here: https://github.com/pillarjs/path-to-regexp
Thanks! I closed the issue
This works for initial load (from URL) but not works when the route is pushed with router.push('/page/article-blabla') resulting in error:
(/page/article-blabla) is incompatible with the href
value (/[lang]/page).
I am trying to add localization to my nextjs project and I was wondering if there is a way to optionally have a dynamic route for the language. For instance if my user went to
/:lang/some-route/:slug
it would use the language variable to determine the localization but optionally/some-route/:slug
would work as well defaulting the user to my default language. Is this possible using next-routes?I believe I can create two routes, one for each case but that doesn't seem elegant as I'd have to duplicate every route in my app.Looks like I can't have two duplicate names for a route :/