VueRouter常见问题汇总

路由可选参数

routerConfig

 {
    path: "/home/mission/:type/:courseid/:missionid",
    name: "Mission",
    props: true,
    component: () =>
        import(
        /* webpackChunkName:'Mission' */
        "@/views/course/mission.vue"
        ),
}

问题

传参时如果少传一个参数 那路由地址将无法正常显示

   this.$router.push({
        name: "Mission",
        params: { type: "add", courseid: item.uuid },
      });

解决

修改 routerConfig

 {
    //  :parmas?  => ? 就是代表参数可选
    path: "/home/mission/:type?/:courseid?/:missionid?",
    name: "Mission",
    props: true,
    component: () =>
        import(
        /* webpackChunkName:'Mission' */
        "@/views/course/mission.vue"
        ),
}
posted @ 2022-05-06 11:33  __Bowen  阅读(56)  评论(0编辑  收藏  举报