红叶都枫了 @163

vue解决二级路由redirect(默认路由)不传参的问题

场景:

pageA----pageB(pageB包含三个二级路由)       

默认进入pageB时进入第一个页面的路由,之后点击左侧按钮,分别进入其他二级路由

原router.js写法:

//应用信息
    {
        path:'/app-manage',
        name:'app-manage',
        component:AppManage,
        redirect:'/app-manage/appMsg',
        children:[
            //应用信息
            {
                path:'/app-manage/appMsg',
                name:'appMsg',
                component:AppMsg,
            },
            ...其他子路由...
        ]
    },
页面路由跳转写法:
<router-link class="lis" tag="li" v-for="(item,index) in side" :to="{path:item.url,query:{appMsg}}" :key="index">
       {{item.name}}
</router-link>
问题,一次进入默认路由时,不传递参数,只有在之后的点击第一个路由时才传递
解决方法:
1.去除router.js的redirect属性
2.在pageB页面第一次页面加载请求到数据后添加
let appMsg = this.appMsg
 this.$router.push({path:'/app-manage/appMsg',query:{appMsg}})
posted @ 2020-06-23 10:11  红叶都枫了163  阅读(1006)  评论(0编辑  收藏  举报