title: VueJs: cannot use router.push
body: <p>So, i want to vue router.push on my store.js, but i keep getting error <code>Cannot read property 'push' of undefined</code></p>
  
  <p>i've tried to import vue-router in my store.js, but still in vain</p>
  
  <p>here's my app.js :</p>
  
  <pre><code>import Vue from 'vue'
  import VueRouter from 'vue-router'
  
  //Import and install the VueRouter plugin with Vue.use()
  Vue.use(VueRouter)
  
  import App from './views/App'
  import Home from './views/Home'
  import Login from './views/Login.vue'
  import Register from './views/Register.vue'
  
  const router = new VueRouter({
      mode: 'history',
      routes: [{
              path: '/',
              name: 'home',
              component: Home,
              meta: { requiresAuth: true }
          },
          {
              path: '/login',
              name: 'login',
              component: Login
          },
          {
              path: '/register',
              name: 'register',
              component: Register
          },
      ],
  });
  
  
  
  const app = new Vue({
      el: '#app',
      components: { App },
      router,
  });
  </code></pre>
  
  <p>and here's my store.js :</p>
  
  <pre><code>import Vue from 'vue'
  import Vuex from 'vuex'
  import axios from 'axios'
  
  Vue.use(Vuex);
  
  export default new Vuex.Store({
      state: {
          accessToken: null,
          loggingIn: false,
          loginError: null
      },
  
      mutations: {
          loginStart: state =&gt; state.loggingIn = true,
          loginStop: (state, errorMessage) =&gt; {
              state.loggingIn = false;
              state.loginError = errorMessage;
          },
          updateAccessToken: (state, accessToken) =&gt; {
              state.accessToken = accessToken;
          },
          logout: (state) =&gt; {
              state.accessToken = null;
          }
      },
  
      actions: {
          doLogin({ commit }, loginData) {
              commit('loginStart');
              console.log(loginData)
  
              axios.post('http://localhost:8000/api/login', loginData)
                  .then(response =&gt; {
                      console.log(response)
                      let accessToken = response.data.jwt;
                      document.cookie = 'jwt_access_token=' + accessToken;
                      commit('updateAccessToken', accessToken);
  
                      ///this caused the error
                      this.$router.push({ path: '/' })
                  })
                  .catch(error =&gt; {
                      // commit('loginStop', error.response.data.error);
                      console.log(error)
                      commit('updateAccessToken', null);
                      console.log(error.response);
                  })
          }
      }
  })
  </code></pre>
  
  <p>as you can see, after i call doLogin() function, and using axios, it stop at the this.$router.push({ path: '/' }) line, causing error.</p>