-
-
Notifications
You must be signed in to change notification settings - Fork 447
Description
I'm looking to get a route of the following format /:category(.*?)*/:pagePrefix('page')?/:page(\d+)?
But currently category will match anything even if I made the pattern inside non greedy, because the catch all of path-to-regexp is greedy and matches the rest
(So /category/sofa/page/1 results in category => [ 'sofa', 'page', '1'] and the rest is empty )
I'm looking for a solution to have the page prefix required only when the page parameter is provided, but did not find a more elegant way to do this because it seems /:category(.*?)*/(page/:page(\d+))? is not a supported syntax, /:category(.*?)*/(page/:page(\d+))? in theory works (if not for the greedy issue) but requires some postprocessing
The problem is that we cannot use just /:category(.*?)/(page/:page(\d+))? either, because then when we compile the route with a category like sofa/armchair then the slash gets url encoded which is not desired behavior
Can't we just make the catch all non greedy (As I see no reason not to and because we currently can't use anything after a catchall, wouldn't be a breaking change) or add a modifier like ? to it to allow non greedy like regex does?