Các phương pháp hay nhất để kiểm tra ủy quyền trước khi lắp đặt thành phần là gì?Cấp phép cho bộ phận phản ứng của bộ định tuyến
tôi sử dụng phản ứng-router 1.x
Dưới đây là tuyến đường của tôi
React.render((
<Router history={History.createHistory()}>
<Route path="/" component={Dashboard}></Route>
<Route path="/login" component={LoginForm}></Route>
</Router>
), document.body);
Đây là thành phần Bảng điều khiển của tôi:
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 làm thế nào bạn kiểm tra mặc dù? từ cookie? từ cuộc gọi máy chủ? Tôi nghĩ rằng nó thường được thực hiện trong 'onEnter' của' Route', thay vì 'componentWillMount'. '
Dylan