on page refresh the created hook happen to be called twice for some weird reasons but that doesn't happen if I come from another route.
created() {
this.$store.dispatch('setInternalComponents',true);
this.getCurrencies();
},
you can find my router configuration below:
Vue.use(VueRouter);
const routes = [
{ path: "/", component: Auth },
{ path: "/resetpassword", component: Resetpwd },
{ path: "/forgotpassword", component: Forgotpwd },
{ path: "/firstlogin", component: FirstLogin},
{
path: "/dashboard",
component: Dashboard,
beforeEnter(to,from,next){
if (store.state.accessToken)
{
next()
}else
next('/')
}
},
{ path: "*", redirect: "/" }
];
export default new VueRouter({
routes: routes,
mode: "history"
});
I've fixed the issue myself. If we update the Vuex store on created/mounted hooks it will re-render the component so I moved the logic on the beforeEnter event in the routes configuration to avoid that behaviour.
code changed below:
{
path: "/dashboard",
component: Dashboard,
beforeEnter(to,from,next){
if (store.state.accessToken)
{
store.dispatch('setInternalComponents',true);
next()
}else
next('/')
}
},
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With