Vue学习-刷新界面动态路由丢失

时间:2025-04-02 13:20:20
//路由守卫 router.beforeEach((to, from, next) => { iView.LoadingBar.start(); //("store",store); //处理刷新界面动态路由丢失问题 let userToken = store.state.users.currentUser.UserToken; if(userToken){ //动态数组丢失说明用户刷新了页面 if(store.state.users.routers.length == 0){ //从localStorage中获取菜单树。然后重新加载路由 let menuRoutes = []; menuRoutes = util.initMenu(menuRoutes,JSON.parse(localStorage.getItem("menuData"))); store.commit('users/updateRouter',menuRoutes); //确保addRoutes()时动态添加的路由已经被完全加载上去。 next({ ...to, replace: true }) }else{ next(); } }else{ next(); } });