FYI, I am using React Router 5. I have following dependency in my package.json:
"react-router-dom": "^5.0.0",
[ Question edited with a more simplified example ]
Let me describe the issue I am facing. All the following URLs
http://localhost:3001/contact
http://localhost:3001/contact/
http://localhost:3001/contact/john50
are matching following route ( with 1 optional param )
<Route path="/contact/:name([A-Za-z]+)?" component={Contact} />
Then, I have updated the above Route by adding another optional param, age. It looks like this:
<Route path="/contact/:name([A-Za-z]+)?:age(\d{2})?" component={Contact} />
Why this new updated route with 2 optional params is matched by this URL :
http://localhost:3001/contact/
and not by this URL :
http://localhost:3001/contact
Jsfiddle for this weird behaviour
Why ? Can someone explain ?