コンポーネントの取り付け前に認可チェックのベストプラクティスは何ですか?リアクタ認可
私はここで反応し、ルータを1.1
を使用する私のルートはここ
React.render((
<Router history={History.createHistory()}>
<Route path="/" component={Dashboard}></Route>
<Route path="/login" component={LoginForm}></Route>
</Router>
), document.body);
ある私のダッシュボードコンポーネントです:
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を行うことができますか?クッキーから?サーバーコールからですか?私はそれが 'componentWillMount'ではなく' Route'の 'onEnter'で一般的に行われていると思います。 '<経路パス='/'コンポーネント= {ダッシュボード} onEnter = {function(nextState、transition){if(!USER_IS_AUTHED){transition.to(' login '); }})} ' – Dylan