ecmascript 6 - React Router v4 + Regex don't like Template Literals -
react router 4.0.0 comes regex validate querystring parameters. however, not seem compatible es6 template literals.
here simple example :
<browserrouter> <switch> <route route path={routeconstant} component={mycomponent} /> </switch> </browserrouter>
if try following values, you'll see first 2 constants work, third not.
const root = 'folder' const routeconstant1 = '/folder/:id(\d+)' // <= /folder/21 matches const routeconstant2 = `/${root}/:id` // <= /folder/21 matches const routeconstant3 = `/${root}/:id(\d+)` // <= /folder/21 not match
there explanation (there is), i'd appreciate few pointers because feels bit confusing. in advance.
ok, posted question fast guess.
the answer in way template literals work : ecmascript 6 - template literals
=> "backslashes not interpreted"
so solution have routeconstant3 work write :
const routeconstant3 = `/${root}/:id(\\d+)`
Comments
Post a Comment