0

I am creating an app, however, I want that when I click Signup, register() executes and upon return of a promise I want to route to the login route.

Instead of staying on the same signup page, I want to route to the login page

register(){

  axios.post('url', {

    username: this.username,
    password:this.password
  })
  .then(function (response) {
    console.log(response);

  })
  .catch(function (error) {
    console.log(error);
  });
2
  • Are you using vue-router? Commented Jun 14, 2017 at 19:25
  • @BertEvans..Yes I am using vue-router Commented Jun 15, 2017 at 10:15

1 Answer 1

2

Use push() on the router.

.then(function (response) {
  console.log(response);
  this.$router.push('login');
})

Vue-router has programmatic navigation.

Sign up to request clarification or add additional context in comments.

3 Comments

Can i export router so I can use it in another component?
@Artwell $router is avaliable on all components.
@BertEvans is correct. And to answer your question, yes, you can also export it to use in another component. Here is an example... github.com/theosherman/insulin-calculator/blob/master/src/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.