最近项目遇到路由,父子路由跳转默认选中路由。每次一看到路由就懵逼
主页面:
导航的菜单是循环路由得出来的,因此点击跳转子页面是这样的
导航菜单代码:
<el-menu router :default-active="defaultActive" mode="horizontal" active-text-color="rgba(68, 100, 255, 1)">
<template v-for="(item,val) in data" >
<el-menu-item :key="val" :index="item.path" v-if="!item.hidden">
<span slot="title" v-if="item.meta.title">{{item.meta.title }}</span>
</el-menu-item>
</template>
</el-menu>
路由写在同级:
因此:index页面就要判断跳转
computed: {
// 监控路由--如果是跳转子路由就判断默认选中主路由
defaultActive(){
let defaultActive = ''
if(this.$route.path === '/publice/production/productionUnit') {
defaultActive = '/publice/production'
} else {
defaultActive = this.$route.path
}
return defaultActive
}
},```