从 Vue 的 iView 组件开始,菜单组件存在一些问题。菜单组件的工作方式与iView 主页上的描述相同,但它并不能反映真实的路由器状态<router-link>
。在浏览器地址栏中输入路线不会将相应的菜单项标记为活动。重定向路由时也会发生此行为。
有谁知道如何处理这个问题?
这是我使用菜单项的源模板:
<Menu mode="horizontal" :theme="theme1" active-name="1">
<MenuItem name="1" to="/">Home</MenuItem>
<MenuItem name="2" to="/about">About</MenuItem>
<MenuItem name="3"
v-if="!isAuthenticated"
@click.native="handleAuth()">Signin</MenuItem>
<Submenu name="3" v-if="isAuthenticated">
<MenuItem name="3-1">Profile</MenuItem>
<MenuItem name="3-2"
@click.native="handleLogout()">Logout</MenuItem>
</Submenu>
</Menu>
还有我的路由器定义:
import Vue from 'vue'
import Router from 'vue-router'
import Home from './views/Home.vue'
import Notfound from './views/Notfound.vue'
import store from './store'
Vue.use(Router)
const router = new Router({
mode: 'history',
base: process.env.BASE_URL,
routes: [
{
path: '/',
name: 'home',
component: Home
},
{
path: '/about',
name: 'about',
component: () => import(/* webpackChunkName: "about" */ './views/About.vue'),
meta: {
requiresAuth: true
}
},
{
path: '/notfound',
name: 'notfound',
component: Notfound
}
]
})
router.beforeEach((to, from, next) => {
// check if authenticated by jwt from store or localstorage
const requiresAuth = to.matched.some(record => record.meta.requiresAuth)
if (!to.matched.length) {
next('/notfound')
return
}
if (requiresAuth && !store.getters.isAuthenticated) {
next({ path: '/' })
} else {
next()
}
})
export default router
对任何提示感到高兴。谢谢