Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React router path as an array

Tags:

react-router

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.

like image 430
beauchette Avatar asked Mar 13 '19 15:03

beauchette


1 Answers

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.

like image 78
Alex Feinman Avatar answered Nov 15 '22 08:11

Alex Feinman