[Vuejs]-Vue instance status and route redirect

0👍

Solved for now attaching the global property to the router instance instead of the Vue instance:

Vue.use(Router)

// global status property
Router.prototype.$isAppInitialized = false

const router = new Router({
    routes: routes
})

router.beforeEach((to, from, next) => {
    if (to.path !== "/" && !router.$isAppInitialized) { 
        next("/")
    }
    else {
        next()
    }
}) 

This works because it is possible to access the router instance in the components and update the global property, but feels like an hack to me. Please let me know if there better ways to do this.

Leave a comment