How to parameterize a route in the Vue?

0

I am using vue/router to make a spa, and I am having difficulty sending the id of a certain product through url ... I'm doing this in the link:

 <router-link :to="{name:'editar',params:{id:item.id}}">editar2</router-link>

route:

 const routes = [{
    path: '/',
    component: Vue.component('home-page')
}, {
    path: '/teste',
    component: Vue.component('home-page')
}, {
    path: '/editar',
    'name': editar,
    component: Vue.component('home-page')
}]
const myRouter = new VueRouter({
    routes
})

But it does not work at all ... how do I make this guy send the id to url ?

    
asked by anonymous 06.08.2018 / 21:38

1 answer

0

You need to specify the parameter name in the route declaration:

{
    path: '/editar/:id',
    name: 'editar',
    component: Vue.component('home-page')
}

And to get the parameter received

$route.params.id or this.$route.params.id

For more information read the vue-router documentation .

    
14.08.2018 / 16:02