6

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.

Andrew Rasmussen
  • 14,912
  • 10
  • 45
  • 81
  • 1
    **For react-router versions** `1.0.0` **and above (including `2.x`), look** [**here**](http://stackoverflow.com/a/35604855/2030321)... – Chris Jul 18 '16 at 11:28

1 Answers1

8

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} />
Andrew Rasmussen
  • 14,912
  • 10
  • 45
  • 81