React Router Authorization
Was sind die Best Practices für die Berechtigungsprüfung vor dem Einbau einer Komponente?
Ich benutze React-Router 1.x
Hier sind meine Routen
React.render((
<Router history={History.createHistory()}>
<Route path="/" component={Dashboard}></Route>
<Route path="/login" component={LoginForm}></Route>
</Router>
), document.body);
Hier ist meine Dashboard-Komponente:
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>
);
}
});