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.

1
  • 1
    For react-router versions 1.0.0 and above (including 2.x), look here... Commented Jul 18, 2016 at 11:28

1 Answer 1

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} />
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.