最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - router-link to path with params - Stack Overflow

programmeradmin0浏览0评论

I'm trying to go to a UserDetail path in my vue app using vue-router.

My routes are :

const routes = [
  { path: '/users', ponent: UserList },
  { path: '/users/:user_id', ponent: UserDetail },
  { path: '/bar', ponent: 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 .html for example) for this type of stuff but how could I use path?

edit #1

mousing over one of the links:

I'm trying to go to a UserDetail path in my vue app using vue-router.

My routes are :

const routes = [
  { path: '/users', ponent: UserList },
  { path: '/users/:user_id', ponent: UserDetail },
  { path: '/bar', ponent: 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/en/api/router-link.html for example) for this type of stuff but how could I use path?

edit #1

mousing over one of the links:

Share Improve this question edited May 14, 2018 at 18:28 timpone asked May 14, 2018 at 17:18 timponetimpone 20k36 gold badges128 silver badges224 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

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.

发布评论

评论列表(0)

  1. 暂无评论