9

I have a code like this :

<BrowserRouter>
  <Switch>
    <Route path="/" exact component={component1} />
    <Route path="/somewhere/:something" component={component2} />
  </Switch>
</BrowserRouter>

I tried this, because in the end, I want to match several paths with the same component / result :

<BrowserRouter>
  <Switch>
    <Route path={["/somewhere/:something","/somewhere2/:something"]} component={component2} />
  </Switch>
</BrowserRouter>

and the path is matched, but my parameter (:something) isnt passed to it. Any idea why ? react-router's docs tells me :

Any valid URL path or array of paths that path-to-regexp@^1.7.0 understands.

1
  • 1
    in fact, I noticed that error : Failed prop type: Invalid prop path of type array supplied to Route, expected string. which is inconsistent with the docs Commented Mar 13, 2019 at 15:31

1 Answer 1

6

The feature was only recently added to React-Router. You need to upgrade your react-router installation to be able to match the documentation and use the feature.

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.