Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 run.

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))
}
like image 918
thau0x01 Avatar asked May 31 '18 17:05

thau0x01


People also ask

How do I push my Vue router?

With Vue Router, you can use its router. push() function to programmatically navigate between routes on your site. You can either call push() with a string path, or with an object containing either the path or name of the route.

How does a router push work?

To navigate to a different URL, use router. push . This method pushes a new entry into the history stack, so when the user clicks the browser back button they will be taken to the previous URL.

How do you pass props through the Vue route?

Vue Router 4 provides multiple ways of doing this: from setting the props property on the route record to true and automatically passing all params as props, setting the props property to a static object to provide static props, or setting it to a function that returns the desired props.


1 Answers

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

Thanks for everyone in comments.

like image 95
thau0x01 Avatar answered Oct 03 '22 08:10

thau0x01