[英]router-link to path with params
I'm trying to go to a UserDetail path in my vue
app
using vue-router . 我正在尝试使用vue-router转到我的vue
app
的UserDetail路径。
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? 我通常将命名路由(例如,请参阅https://router.vuejs.org/en/api/router-link.html )用于这种类型的路由,但是如何使用路径?
mousing over one of the links: 将鼠标悬停在链接之一上:
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
. 如果要传递这样的参数,则应在:to
内使用name
而不是path
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.