Reagir a autorização do roteador
Quais são as melhores práticas para verificação de autorização antes da montagem de um componente?
Eu uso o react-router 1.x
Aqui estão minhas rotas
React.render((
<Router history={History.createHistory()}>
<Route path="/" component={Dashboard}></Route>
<Route path="/login" component={LoginForm}></Route>
</Router>
), document.body);
Aqui está o meu componente Painel:
var Dashboard = React.createClass({
componentWillMount: function () {
// I want to check authorization here
// If the user is not authorized they should be redirected to the login page.
// What is the right way to perform this check?
},
render: function () {
return (
<h1>Welcome</h1>
);
}
});