Skip to content

Commit

Permalink
解决了路由重复添加的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
lsgwr authored and gitee-org committed Nov 26, 2019
1 parent 7529819 commit ed43479
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions code/frontend/src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const routes = [
}
]

const router = new VueRouter({
let router = new VueRouter({
routes
})

Expand Down Expand Up @@ -82,7 +82,10 @@ function addDynamicMenuAndRoutes (userName, to, from) {
let dynamicRoutes = addDynamicRoutes(res.data)
// Todo:下面这两行很精巧,重点理解下
router.options.routes[0].children = router.options.routes[0].children.concat(dynamicRoutes)
router.addRoutes(router.options.routes)
// 重新设置router,要不每次都addRoutes会导致路由重复添加
router = new VueRouter({
routes
})
store.commit('menuRouteLoaded', true)
store.commit('setNavTree', res.data)
})
Expand Down

0 comments on commit ed43479

Please sign in to comment.