vue-router嵌套子路由遇到的问

需求是,我需要点击v-for循环出来的列表项,然后转跳到对应的UserDetail组件,我的路由这样写,没有出现转跳,哪里写错了没?
路由:

const router = new VueRouter({
  routes: [
    {
      path: '/user', 
      component: User,
      name: 'user',
      children: [
        { path: ':userId', component: UserDetail,name:'detail'},
      ]
    },
    {
      path: '/about', 
      component: About,
      name: about
    }
  ]
})

User.vue:

<template>
    <div v-for="(user,index) in users" @click="goDetails(index)">{{user.name}}</div>
    <router-view></router-view>
</template>
<script>
    export default {
        data(){
            return {
                users: [{name:'abby'},{name:'cici'},{name:'jane'}]
            }
        },
        methods:{
            goDetails(index){
                this.$router.push({
                    params: {userId: index}
                })
            }
        }
    }
<script>

UserDetail:
图片描述

阅读 3.5k
2 个回答
goDetails(index){
    this.$router.push({
        name: "user",
        params: {userId: index}
    })
}
this.$router.push({
    params: {userId: index}
})
里面没有path或者name,只有参数。
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题