[Vuejs]-Vue js how to set a default router path to navigate when the web app loads

0👍

I’ve to add redirect property to the admin-panel route.

0👍

Personally for these cases I use an afterEach hook in the routes file:

router.afterEach((to, from) => {
  let exist = false

  for (let i in this.a.options.routes) {
    if (this.a.options.routes[i].name === to.name) {
      exist = true
    }
  }

  if (!exist) {
    this.a.push({
      name: from.name
    })
  }
})

You can use another hook as beforeEach (I do not remember exactly why we use after). Basically the goal is to go through the list of routes, if it does not exist, it returns you to the route you are currently on, which really means that you do not notice any changes, it just does not change the route.

Leave a comment