Nested Browser router
A Nested Browser Router that can be used with React Router, when you want to set a basename on a sub router.
Usage
npm install nested-browser-router
import BrowserRouter from 'react-router-dom';import NestedBrowserRouter from 'nested-browser-router'; { return <BrowserRouter ="/path1"> <Switch> ... <NestedBrowserRouter> <Switch> ... </Switch> </NestedBrowserRouter> </Switch> </BrowserRouter>}
Why?
React Router doesn't support nesting BrowserRouter, but sometimes you need to set a basename for a subsection of your application.
Broken example
The following does not work with React Router - try clicking Home and Sub in the two nav bars:
{ return <BrowserRouter> <> <Link ="/">Home</Link> <Link ="/sub">Sub</Link> <Switch> <Route ="/" = /> <Route ="/sub" = /> </Switch> <BrowserRouter =""> <> <Link ="/">Home</Link> <Link ="/sub">Sub</Link> <Switch> <Route ="/" = /> <Route ="/sub" = /> </Switch> </> </BrowserRouter> </> </BrowserRouter> ;}