[Vuejs]-How to update root data in vue router beforeEach

0👍

this is my code,it worked for me.

// define router
const createRouter = () => new Router({
  routes: constantRoutes,
  isAddDynamicMenuRoutes: false
})
// beforeEach 
if (router.options.isAddDynamicMenuRoutes) {
  next()
} else {
  router.options.isAddDynamicMenuRoutes = true
  ...
  next({ ...to, replace: true })
}

Leave a comment