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))
}
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.
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.
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.
Solved, i changed the method this.$router.push()
from my code, to this.$router.go('/')
.
Thanks for everyone in comments.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With