0
votes

I am trying to redirect the page but I get an error. I think my definitions are correct, why am I getting this error?

Thank you for your help in advance, thankfully you are there.

router.js

import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router);

import Homepage from './screens/Homepage';
import Journey from './screens/Journey';

const router = new Router({
  mode: 'history',
  routes: [
    {
      path: '/',
      component: Homepage
    },
    {
      path: '/journey',
      component: Journey
    }
  ]
});

export default router;

main.js

import Router from './router';
new Vue({
  store: Store,
  router: Router,
  el: '#app',
  render: h => h(App)
});

my Push..

this.$router.push('/journey');
1
In which file do you write this.$router.push('/journey'), is it in a component?Shaya Ulman
Yes, it is written in a component in the Homepage. @ShayaUlmanuser12883832
Can you please post the code?Shaya Ulman
Now fixed. Problem is "setTimeout". I'm remove setTimeOut, now working.. Thanks for help Shaya...user12883832

1 Answers

0
votes

I think the this keyword is undefined at the place where you've written this.$router.push('/journey');. So to avoid this at the top of the block scope you can assign this keyword to a variable and then use that variable instead of this.

// Declare this at the top or first line of the function or block scope
let self = this 
.
.
.
.
self.$router.push('/journey');