Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

权限路由判断 #90

Closed
1 task
strongyc opened this issue May 22, 2022 · 2 comments
Closed
1 task

权限路由判断 #90

strongyc opened this issue May 22, 2022 · 2 comments

Comments

@strongyc
Copy link

Basic Info

What problem does this feature solve?

在源码中点击菜单栏进行跳转
const goto = (item: RouteRecordRaw) => {
router.push({
name: item.name,
});
};
export default function setupServerPermissionGuard(router: Router) {
router.beforeEach(async (to, from, next) => {
// A simple example 简单示例

// 针对来自服务端的菜单配置进行处理
// Handle routing configuration from the server

// 根据需要自行完善来源于服务端的菜单配置的permission逻辑
// Refine the permission logic from the server's menu configuration as needed
const appStore = useAppStore();
if (appStore.menuFromServer) {
  const serverMenuConfig = [...appStore.appServerMenuConfig, ...whiteList];
  let exist = false;
  while (serverMenuConfig.length) {
    const element = serverMenuConfig.shift();
    if (element?.name === to.name) exist = true;

    if (element?.children) {
      serverMenuConfig.push(
        ...(element.children as unknown as RouteRecordNormalized[])
      );
    }
  }
  if (exist) next();
  else next({ name: 'notFound' });
} else {
  next();
}

});
}

What are the similar cases of this feature

该种方式通过name进行跳转,但实际开发中,路径是会带参数传递,带参数传递传递的路径该如何进行权限判断,是否能在Pro
中给一个案例,比如个人中心详情

@sHow8e
Copy link
Member

sHow8e commented May 23, 2022

@strongyc hihi 你提的这些是vue-router的使用问题。路由守卫函数的to参数里面有query信息。router相关文档

@strongyc
Copy link
Author

收到,感谢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants