使用得关键技术:
- new Router得matcher,替换路由,解决登录角色切换时,路由重复问题
- router.onReady方法,在页面刷新时,静态路由加载完成执行,重新调用addRouters动态添加路由(通配符404路由要动态在最后添加)
1、从后端获取菜单,我的json格式如下:
[{ "id": "c377b2ec3add4a2cb757e20f97996a5a", "createDate": "2021-03-31 11:40:00", "updateDate": "2021-03-31 11:56:12", "createBy": null, "updateBy": "", "delFlag": 1, "systemFlag": "service-mdinfo", "parentId": "", "menuName": "咨询互动", "menuOrder": 1, "showFlag": 1, "sort": 20, "icon": "fa fa-user-o", "path": "/", "component": "Home.vue", "sonList": [ { "id": "0c6082ff312f40e9b396d03e54c7aef3", "createDate": "2021-03-31 11:43:47", "updateDate": null, "createBy": null, "updateBy": null, "delFlag": 1, "systemFlag": "service-mdinfo", "parentId": "c377b2ec3add4a2cb757e20f97996a5a", "menuName": "咨询管理", "menuOrder": 2, "showFlag": 1, "sort": null, "icon": null, "path": "/zixun", "component": "zixun/zixun.vue", "sonList": null } ] }] |
2、把后端菜单转换为routers对象
|
3、登录跳转前执行
路由相关方法 |
4、页面刷新时,onReady方法
|