在react-boilerplate中实现用户角色授权

时间:2016-11-22 06:25:48

标签: authentication reactjs react-router react-boilerplate

所以我正在尝试使用react-boilerplate在React中实现用户角色/权限实现。但是,与标准

相比,此处使用的路由以某种方式dynamic

<Router> <Route><Route> </Router>

格式。

现在我已经看到react-router的这个函数onEnter,我的同事告诉我,这可能对用户角色有用。

所以我想知道是否有办法通过动态路由访问它?根据我在react-boilerplate的路由代码段中看到的内容,我无法声明它。

应用/ routes.js

 ....
 return [
    {
      path: '/',
      name: 'home',
      getComponent(nextState, cb) {
        const importModules = Promise.all([
          System.import('pages/Login'),
        ]);

        const renderRoute = loadModule(cb);

        importModules.then(([component]) => {
          renderRoute(component);
        });

        importModules.catch(errorLoading);
      },
    }, {
      path: '/pt',
      name: 'home-pt',
      getComponent(nextState, cb) {
        const importModules = Promise.all([
          System.import('pages/Home'),
        ]);

        const renderRoute = loadModule(cb);

        importModules.then(([component]) => {
          renderRoute(component);
        });

        importModules.catch(errorLoading);
      },
      childRoutes: [
        {
          path: '/pt/info/share',
          name: 'pt-share-info',
          getComponent(nextState, cb) {
            const importModules = Promise.all([
              System.import('pages/Share'),
            ]);

            const renderRoute = loadModule(cb);

            importModules.then(([component]) => {
              renderRoute(component);
            });

            importModules.catch(errorLoading);
          }
        }, {
          path: '/pt/info/request',
          name: 'home-pt',
          getComponent(nextState, cb) {
            const importModules = Promise.all([
              System.import('pages/Request'),
            ]);

            const renderRoute = loadModule(cb);

            importModules.then(([component]) => {
              renderRoute(component);
            });

            importModules.catch(errorLoading);
          }
        }
      ]
    },  {
      path: '*',
      name: 'notfound',
      getComponent(nextState, cb) {
        System.import('containers/NotFoundPage')
          .then(loadModule(cb))
          .catch(errorLoading);
      },
    },
  ];

PS。我也看过这个react-router-role-authorization,并且想知道我是否可以将它与react-boilerplate的当前设置集成?

0 个答案:

没有答案