Reputation: 15099
I'm trying to create a route that matches all of the following URLs:
/product/foo
/product/foo/bar
Here's my current route:
<Route path="/product/:productName(/:urlID)" handler={SomeHandler} />
According to the documentation on https://github.com/rackt/react-router/blob/master/docs/guides/basics/RouteMatching.md this route should match perfectly but it does not match either of the URLs above.
What do I need to do to support this optional parameter?
I'm on React Router version 0.13.3 and if I remove the (/:urlID)
then I can match the first URL but not the second.
Upvotes: 6
Views: 9550
Reputation: 15099
Okay so the () syntax is specific to React Router 1.0, not 0.13.3. I ended up using the ? syntax:
<Route path="/product/:productName/?:urlID?" handler={SomeHandler} />
Upvotes: 8