I'm new to react and previously I was using angular. Now I'm trying to build an app with react router v4. My current task sounds very simple: I want to add preloader and some authentication checkings for routes. In angular I would use events like 'routechangestart', 'routechangesucess' and resolve for authentication checking. However, I checked router documentation and I have't found none of this. Single option I saw is to use history.listen(), but it triggers only after route has changed. So my question is: how do I know when route starts changing, it has changed and what routes it were.
Here is how my router looks like (I want to handle this information in preloader component):
ReactDOM.render(
<Router>
<Provider store={store}>
<AppContainer>
<div>
<Preloader/>
<Switch>
<Route exact path="/" component={Header}/>
<Route path="/app" component={App}/>
<Route path="/content" component={Content}/>
<Route path="*" component={Landing}/>
</Switch>
</div>
</AppContainer>
</Provider>
</Router>,
document.getElementById('main')
);
Aucun commentaire:
Enregistrer un commentaire