3

index js file

I used vue router programatically but it didn't working for me.I searched through the web and everyone used this.$router.push().

import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/HelloWorld'
import BecomeHost from '@/components/BecomeHost'

Vue.use(Router)

export default new Router({
 routes: [
 {
  path: '/',
  name: 'HelloWorld',
  component: HelloWorld
 },
 {
  path: '/become_host',
  name: 'BecomeHost',
  component: BecomeHost
 }
]})

component.vue

I called like below when response sucess but not working

if (res.data.status === 'success') {
    localStorage.setItem('user', JSON.stringify(res.data.data))
    let user = JSON.parse(localStorage.getItem('user'))
    this.setUserData(user)
    this.$router.push('/become_host')
}
1
  • When you say it's not working, can you explain a bit more? What's doing or not doing? Is it going through $router.push? Do you have any error in the console? Commented Sep 11, 2018 at 6:28

2 Answers 2

2

you can try it like below

this.$router.push({path: 'become_host'})
// or
this.$router.push('BecomeHost')
Sign up to request clarification or add additional context in comments.

Comments

2

You can use push with props, more details here

In your case I think, you need something like this:

this.$router.push({ path: 'become_host' })

OR

this.$router.push({ name: 'BecomeHost' })

Comments

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.