[Vuejs]-How is $route object initialized?

0👍

When you’r on the /network-error route, the app is above that, so you can’t say in the app where are you in my app ?

Because your application at this time created and mounted the view app and after go inside the route detected.

The good and normal practice is to fetch every route before like a middleware, inside your router.js or routes/index.js use this function:

router.beforeEach(async (to, from, next) => {
  if (to.name === 'BlackHole') {
    next({ name: 'NetworkError' })
  }
  next()
})

This maybe doesn’t not exactly match your redirect because i miss some information, but i think you understand what you have to do.

0👍

The problem was because the route load is an async process, I found a very quick solution here, just add this line of config to main.js:

router.isReady().then(() => {app.mount('#app')})

https://www.youtube.com/watch?v=a6gT6qHtch8&ab_channel=VueMastery

Leave a comment