Answer the question
In order to leave comments, you need to log in
Is it possible to use regex variables in react-router's path?
Actually there is a working code:
<Route path='/section/:id(\d+)' component={EditSection} />
<Route path={'/section/:id(\d+)'} component={EditSection} />
const pathVariable = '/section/:id(\d+)';
<Route path={pathVariable } component={EditSection} />
Answer the question
In order to leave comments, you need to log in
As a result, the problem turned out to be that curly braces are escaped, as opposed to writing through quotes. The solution turned out to be as simple as possible, write \\d instead of \d.
Because the regular expression needs to be escaped, you are now passing it as a simple string. Try to navigate by id with regular expression characters, you should have an EditSection component open.
Take a look here Regular expressions several chapters - and you will figure out your problem
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question