Router: Can we use a Regex to match several paths while declaring a route ?

Created on 31 Jan 2019  路  4Comments  路  Source: reach/router

Can we use a Regex to match several paths while declaring a route ?

Most helpful comment

Hi,
It would be nice to have more control over matched parameters as well, such as in Express.js:

https://expressjs.com/en/guide/routing.html#route-parameters

To have more control over the exact string that can be matched by a
route parameter, you can append a regular expression in parentheses (()):

Route path: /user/:userId(\d+)
Request URL: http://localhost:3000/user/42
req.params: {"userId": "42"}

It would reduce the need to do custom routing within components after testing parameters.

All 4 comments

Hi,
It would be nice to have more control over matched parameters as well, such as in Express.js:

https://expressjs.com/en/guide/routing.html#route-parameters

To have more control over the exact string that can be matched by a
route parameter, you can append a regular expression in parentheses (()):

Route path: /user/:userId(\d+)
Request URL: http://localhost:3000/user/42
req.params: {"userId": "42"}

It would reduce the need to do custom routing within components after testing parameters.

Was this ever done? I need this feature for my project

I'm very disappointed that there doesn't seem to be support for regex-based path matching, as the default React Router allows. I may need to return to the standard React Router because of this.

I need this feature too

Was this page helpful?
0 / 5 - 0 ratings

Related issues

thupi picture thupi  路  4Comments

MarioKrstevski picture MarioKrstevski  路  3Comments

benwiley4000 picture benwiley4000  路  4Comments

ricardobrandao picture ricardobrandao  路  5Comments

florian-bd picture florian-bd  路  3Comments