I have a react page that renders either a login page or navbar + container component based on the current route. I do not want the navbar to be visible with login page. My app is thus structured as follows:
index.js
ReactDOM.render(<Main/>, document.getElementById('root'));
Main.js
<Router>
<Switch>
<Route path="/login" component={Login} />
<PrivateRoute path="/" component={App} />
</Switch>
</Router>
App.js
<Router>
<div className="App">
<Navbar/>
<div className="main-container">
<Switch>
<Route exact path="/" component={Container1}/>
<Route path="/route1" component={Container2}/>
<Route path="/route2" component={Container3}/>
</Switch>
</div>
</div>
</Router>
Now if in inside any of the Container components I want to do a this.props.history.push('/login') it only affects the closest < Switch > and thus not rendering anything in the container area (since no routes match) but keeping the navbar visible. How could I get the parent < Switch > from Main.js to decide what to render on programmatic route change? Should I structure the app in some other way?
Thanks.