Reputation: 2593
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')
}
Upvotes: 3
Views: 45
Reputation: 6474
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' })
Upvotes: 2
Reputation: 164
you can try it like below
this.$router.push({path: 'become_host'})
// or
this.$router.push('BecomeHost')
Upvotes: 2