Quali sono le migliori pratiche per il controllo dell'autorizzazione prima del montaggio di un componente?Autorizzazione router di prova
Io uso reagiscono-router 1.x
Qui sono i miei percorsi
React.render((
<Router history={History.createHistory()}>
<Route path="/" component={Dashboard}></Route>
<Route path="/login" component={LoginForm}></Route>
</Router>
), document.body);
Qui è la mia componente Dashboard:
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>
);
}
});
https://github.com/rackt/react-router/tree/master/examples/auth-flow come stai controllando però? da un cookie? da una chiamata al server? Penso che in genere sia fatto in 'onEnter' del' Route', piuttosto che in 'componentWillMount'. '
Dylan