Home

Issue: 205

`this.$router.replace` not works well

[issue link]
<button @click="logout">Logout</button>

export default {
  fetch ({store, redirect}) {
    if (!store.state.authUser) {
      return redirect('/login')
    }
  },
  methods: {
    logout () {
      this.$store.dispatch('logout');
//      this.$nuxt.$router.replace({ path: 'login' });
//      this.$nuxt.$router.replace({ path: 'test' });
      window.location.href = 'login';
    }
  }
}

In this case, when i use this.$nuxt.$router.replace({ path: 'test' }), i am redirected to localhost:3000/test and it requested localhost:3000/api/users/test at the sametime.
But when i use this.$nuxt.$router.replace({ path: 'login' }), it didn’t redirect. And in vue-dev-tools, i can see it didn’t emit an routeChanged event.
As a workaround, i use window.location.href = 'login' temporarily.
I don’t know if $router in a method page is the right way to browser redirects.

Thanks in advance for awesome nuxt.

This question is available on Nuxt.js community (#c174)