Vue Router this.$router.push not working on methods

thau0x01 picture thau0x01 · May 31, 2018 · Viewed 42.6k times · Source

i'm doing login, but after the login methods gets success, i'm pushing a route for the $router object and it's not working, can someone help me?

my code:

doLogin(){
       this.attemptLogin({...this.user}).then(function(){
            this.$router.push('/') 
            } )
  },

So, the login methods execute as expected, but the callback this.$router.push('/') does not runs

my attemptLogin is an action, it's code is following:

export const attemptLogin = ( {commit}, user) => {
    return http.post('login', {
        'email': user.email,
        'password': user.password
    }).then(response => {
        return commit(types.setToken, response.data)
    }).catch( e => console.log(e))
}

Answer

thau0x01 picture thau0x01 · May 31, 2018

Solved, i changed the method this.$router.push() from my code, to this.$router.go('/').

Thanks for everyone in comments.