I am using Vaadin Hilla and like to define a route in my typescript frontend routes.ts
with an optional named parameter for the language which should be optional like :lang?
. The optional language parameter should follow a reg-exp pattern for two alphabetical character \w{2}
.
So the route should match:
- /categoryA/categortyB/...
- /en/categoryA/categoryB/...
- /de/categoryA/categoryB/...
I tried multiple multiple variants for the path, but I could not make the named parameter :lang
optional when I use a regexp pattern like :lang(\\w{2})?
or :lang(\\w{2}?)
or :lang((\\w{2})?)
. The only thing which seems to work is :lang?
Any suggestions?
import type { Commands, Context, Route } from '@vaadin/router';
...
export const routes: Route[] = [
{
path: '/:lang(\\w{2})?/:cat*',
component: 'route-test-view',
action: async (_context, _command) => {
await import('./views/route-test-view');
return;
},
}
];
...
- Link to Hilla Route documentation
- Link to Path-To-Regexp