Reputation: 19929
I'm trying to go to a UserDetail path in my vue
app
using vue-router.
My routes are :
const routes = [
{ path: '/users', component: UserList },
{ path: '/users/:user_id', component: UserDetail },
{ path: '/bar', component: Bar }
]
And router link :
<td><router-link :to = "{ path: 'users/:user_id', params: {user_id: user.id}} ">{{user.name}}</router-link></td>
But this is clearly not the correct syntax. I normally used named routes (see https://router.vuejs.org/en/api/router-link.html for example) for this type of stuff but how could I use path?
mousing over one of the links:
Upvotes: 1
Views: 6569
Reputation: 3383
The solution is simple. Just do like router-link docs says:
<td>
<router-link :to="{ name:'users', params: { user_id: user.id }}">
{{user.name}}
</router-link>
</td>
If you want to pass the parameters like this, you should use name
instead of path
inside the :to
.
Upvotes: 8