Is there a way to validate path parameters pre-route matching?
Is there a way to validate path parameters pre-route matching?
I have multiple URLs with optional parameters like these ones:
/{-$locale}/{$category}/$articleSlug
/{-$locale}/{$branch}/$slug
But in the end the route matching picks the wrong route and thinks a category is a locale. If I could add a regex validation or something to the ${-locale<(en|de|fr)>} that would be great.
Right now the only solution I can think of is to have a catch-all route & handle it case-by-case.3 Replies
deep-jade•2w ago
we dont have this right now, @bostonsheraff any idea if this is feasable in the future?
eastern-cyan•2w ago
"feasible" 100%, might tank performance though, we'd have to measure
my recommendation would be to use prefixes like
/{-$locale}/c-{$category}/$articleSlug, but I understand this is not to everyone's tasteplain-purpleOP•2w ago
Got it. Indeed we don't really want to use
c-{$category} so for now I think my only option is the catch-all route.
Maybe instead of allowing a regex which could complicate route matching quite a bit, even allowing a validation callback would help, like params.matches or params.isValidMatch.
Then as you go through the routes trying to find a match you also call that method.
But that's just my 2 cents. I don't know the in-depth implementation details so what I suggest might not be feasible or just as complicated.
Either way, thanks a lot for the replies!