Skip to content

请问路由配置可以动态的改变吗? #293

Closed
@reuwi

Description

@reuwi
Contributor

我们现在想要增加一个功能,就是管理员可以更改每个菜单的可访问角色列表,我想在进入页面之前从服务器获取每个路由的可访问列表并更改,请问这样子可以实现吗?

Activity

PanJiaChen

PanJiaChen commented on Nov 22, 2017

@PanJiaChen
Owner

只要将 @/router/index.js 中的 asyncRouterMap 存在服务端就可以,原理和现有逻辑是差不多的,后续可能会改成可配置的形式。
Duplicate of #167
后续可关注该issue

reuwi

reuwi commented on Nov 22, 2017

@reuwi
ContributorAuthor

请问可以详细的指点下吗?

将 @/router/index.js 中的 asyncRouterMap 存在服务端

大概应该怎样实现呢?因为asyncRouterMap还跟components相关联,因此不太理解应该怎样实现,非常感谢~

PanJiaChen

PanJiaChen commented on Nov 22, 2017

@PanJiaChen
Owner

再做一个asyncRouterMap.components的name 和 本地components 做一个映射

const map={
 login:require('login/index').default // 同步的方式
 login:()=>import('login/index')      // 异步的方式
}
//你存在服务端的map类似于
const serviceMap=[
 { path: '/login', component: 'login', hidden: true }
]
//之后遍历这个map,动态生成asyncRouterMap
并将 component 替换为map[component]
reuwi

reuwi commented on Nov 22, 2017

@reuwi
ContributorAuthor

非常感谢,按照您的方法已经成功实现了~

reuwi

reuwi commented on Jan 18, 2018

@reuwi
ContributorAuthor

@PanJiaChen 请问asyncRouterMap在服务器端怎么存取比较好?目前我们公司的后台给的解决方案是把name和role作为两个字段存在数据库中,其它字段作为一个payload存起来,获取asyncRouterMap时候再拼出来,这样子的实现感觉很奇怪,请问有什么好的实现方法吗?

reuwi

reuwi commented on Jan 18, 2018

@reuwi
ContributorAuthor

目前角色管理页就是用树状表格来实现的
_20180118095844

PanJiaChen

PanJiaChen commented on Jan 18, 2018

@PanJiaChen
Owner

name 和 role作为存储的关键词也没什么问题,选择自己合适的交互方式就行了,反正前端总归需要洗数据的。

flyliao

flyliao commented on Apr 9, 2018

@flyliao

@gaoshijun1993 能提供怎么实现后台动态权限的实现么?后端人员确实不知道前端怎么整理。

reuwi

reuwi commented on Apr 9, 2018

@reuwi
ContributorAuthor

105 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @amoydavid@HoHo1@yyggg@vini123@wwlleo0730

        Issue actions

          请问路由配置可以动态的改变吗? · Issue #293 · PanJiaChen/vue-element-admin