我正在尝试在mainMenu的subMenu显示列表上实现功能路由的项目。每个subMenu都有自己的特定名称,我想要追加,并根据subMenu的名称路由到我想要的route.path
。
模板
<li v-for='child in item.children'>
<a href="#" v-on:click.prevent="navigate(child.text)">{{child.text}}</a>
<!--<router-view v-bind:to="'/trafficSetting/' + child.text">{{ child.text }}</router-view>-->
</li>
脚本
navigate (to) {
alert(to)
this.$router.push(to)
}
Main.JS
Vue.use(VueRouter)
Vue.use(VueResource)
// Vue.use(MintUI)
// define routes
const Home = resolve => require(['./components/home.vue'], resolve)
const trafficSetting = resolve => require(['./components/trafficSetting.vue'], resolve)
const seedResourcesManagement = resolve => require(['./components/seedResourcesManagement.vue'], resolve)
const driverUserManagement = resolve => require(['./components/driverUserManagement.vue'], resolve)
const whiteblackListManagement = resolve => require(['./components/whiteblackListManagement.vue'], resolve)
const VPNserverManagement = resolve => require(['./components/VPNserverManagement.vue'], resolve)
const routes = [
{path: '/', component: Home},
{path: '/trafficSetting', name:'trafficS', component: trafficSetting},
{path: '/seedResourcesManagement', component: seedResourcesManagement},
{path: '/driverUserManagement', component: driverUserManagement},
{path: '/whiteblackListManagement', component: whiteblackListManagement},
{path: '/VPNserverManagement', component: VPNserverManagement}
]
这导致
Uncaught TypeError: Cannot read property 'push' of undefined
我该如何解决这个问题?
答案 0 :(得分:0)
你没有声明路由器,所以试试这个:
const router = new VueRouter({
routes = [
{path: '/', component: Home},
{path: '/trafficSetting', name:'trafficS', component: trafficSetting},
{path: '/seedResourcesManagement', component: seedResourcesManagement},
{path: '/driverUserManagement', component: driverUserManagement},
{path: '/whiteblackListManagement', component: whiteblackListManagement},
{path: '/VPNserverManagement', component: VPNserverManagement}
]
})