只有管​​理员才能访问该页面?

时间:2020-03-09 19:23:51

标签: reactjs

只有我的管理员才能在项目中访问sns.set(style='whitegrid') plt.figure(figsize=(20,20)) sns.barplot(df.genres.value_counts().index, df.genres.value_counts()) plt.xticks(rotation=45) plt.xlabel('genres') plt.ylabel('Count', rotation=0) plt.title('Graph showing the count for each genre in the dataset') plt.legend();

这是我在模块配置中的代码:

/page/admin

这是我的身份验证角色:

 auth    : authRoles.admin,
routes  : [
    {
        path    : '/page/admin',
        component: React.lazy(() => import('./Page')),
    },
],
auth    : authRoles.notadmin,
routes  : [
    {
        path     : '/page',
        component: React.lazy(() => import('./Page'))
    }
  //
]

const authRoles = { Admin : ['Admin'], NotAdmin : ['Admin', 'User'],}; page/admin

不同

但是“ NotAdmin”用户也可以访问/page

1 个答案:

答案 0 :(得分:0)

让我们尝试了解您的问题。我认为您正在使用React Router。如果是,则必须创建一个PrivateRoute,那么您应该能够检查某人是否已通过身份验证或具有某种角色。看一下这个页面。 https://reacttraining.com/react-router/web/example/auth-workflow

相关问题