remix-run / react-router

Declarative routing for React
https://reactrouter.com
MIT License
52.81k stars 10.23k forks source link

Multiple Routers break routing #6737

Closed gyuhyeon closed 5 years ago

gyuhyeon commented 5 years ago

Version

5.0.0

Test Case

https://codesandbox.io/s/3v04q4prrq

Steps to reproduce

Have multiple Routers defined in order to utilize basenames. There are cases when this is required especially in enterprise level setups, where multiple different servers reverse proxy onto a single frontend react dedicated server with different unique routes as : /finance/mobile/web, /order/mobile/web, /point/web. It's not exactly fun to append all those routes on to the routing config if there are 400+ unique urls.

Expected Behavior

<Router basename="/foo">
    <div>
    <Switch>
        <Route exact path="/about" component={About} />
    </Switch>
    </div>
</Router>
<Router basename="/bar">
    <div>
    <Switch>
        <Route exact path="/about" component={About} />
        <Route component={NotFound} />
    </Switch>
    </div>
</Router>

Actual Behavior

Last words

Thank you.

timdorr commented 5 years ago

The basename prop is meant to emulate the <base> tag, of which, there can only be one on a page at a time.

What you're looking for here is a top level BrowserRouter to drive the interaction with the DOM history, and many MemoryRouters underneath that to handle several sections of your application.