絕大多數項目都需要路由的介入,接下來是在jboot-env中,路由的相關配置:
```
//路由表配置
context.$configure.set('routerTable', function(redirect){ //redirect會自動生成重定向路徑。切記:沒有子菜單時,不要使用redirect屬性!
return {
other: [ //不需要權限過濾的菜單,自動存放在store的otherMenus中。同時這些菜單會直接添加至router中。
{
name: 'login',
path: '/login',
component: require('views/login/index').default
}
],
permission: [ //需要權限過濾的菜單,自動存放在store的permissionMenus中。加載完菜單數據后,可以將這些菜單通過addRoutes添加到路由之中
{
name: 'homepage',
path: '/homepage',
redirect, //訪問 /homepage 路徑時,會自動重定向至homeIndex
component: require('views/homepage/index').default,
children: [
{
name: 'homeIndex',
.....
}
]
}
]
}
});
```
具體配置與VueRouter的配置一致。
關于router的全局鉤子配置如下:
```
//跳轉之前的鉤子
context.$configure.set('routerBefore', function(to, from, next){
... //您的邏輯
});
//跳轉之后的鉤子
context.$configure.set('routerAfter', function(to, from){
... //您的邏輯
});
```