控制路由器中的用户权限-具有子路由的路由

时间:2019-03-28 07:42:35

标签: reactjs redux routes

我正在尝试在React应用中实现用户权限。

我的App.js文件如下:

const routes = {

  path: '/',
  indexRoute: { onEnter: (nextState, replace) => replace('/login') },
  childRoutes: [

    require('./routes/dashboard').default,
    require('./routes/settings').default,

  ]
};

ReactDOM.render((

    <Provider store={store}>
    <Router
      history={history}
      routes={routes}/>
</Provider>
), document.getElementById('root'));


如何根据用户权限在此处控制子路由? 示例:如果我只需要访问DashboardView。我该如何控制?

仪表板组件在index.js文件中具有许多关联的子路由。像这样:

export default {
    path: dashboard
    component: require('../../demo').default,

    childRoutes: [
        {
            path: 'user',
            getComponent(nextState, cb){
                System.import('./createDemo').then((m)=> {
                    cb(null, m.default)
                })
            }
        },
        {
            path: role
            getComponent(nextState, cb){
                System.import('./createDemo1').then((m)=> {
                    cb(null, m.default)
                })
            }
        }

    ]
};

0 个答案:

没有答案