6
votes

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.

1
For react-router versions 1.0.0 and above (including 2.x), look here...Chris

1 Answers

8
votes

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} />