我尝试使用 vue-router 转到vue
app
的UserDetail路径。
我的路线是:
const routes = [
{ path: '/users', component: UserList },
{ path: '/users/:user_id', component: UserDetail },
{ path: '/bar', component: Bar }
]
和路由器链接:
<td><router-link :to = "{ path: 'users/:user_id', params: {user_id: user.id}} ">{{user.name}}</router-link></td>
但这显然不是正确的语法。我通常使用命名路由(例如参见https://router.vuejs.org/en/api/router-link.html)这类东西,但我怎么能使用路径?
答案 0 :(得分:0)
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
.