小编the*_*heo的帖子

反应路由器授权

在组件安装之前进行授权检查的最佳做法是什么?

我使用react-router 1.x

这是我的路线

React.render((
  <Router history={History.createHistory()}>
    <Route path="/" component={Dashboard}></Route>
    <Route path="/login" component={LoginForm}></Route>
  </Router>
), document.body);
Run Code Online (Sandbox Code Playgroud)

这是我的仪表板组件:

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>
    );
  }
});
Run Code Online (Sandbox Code Playgroud)

javascript authorization reactjs react-router

60
推荐指数
2
解决办法
3万
查看次数

标签 统计

authorization ×1

javascript ×1

react-router ×1

reactjs ×1