You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.7 KiB
55 lines
1.7 KiB
// 引入 Vue 核心库
|
|
import Vue from 'vue';
|
|
|
|
// 配置路由:引入 VueRouter 插件
|
|
import VueRouter from 'vue-router';
|
|
Vue.use(VueRouter); // 安装 VueRouter 插件
|
|
|
|
// 1. 创建组件:导入需要用到的页面组件
|
|
import Index from '@/views/index'; // 主页框架(包含头部、侧边栏等)
|
|
import Home from '@/views/home'; // 首页内容组件
|
|
import Login from '@/views/login'; // 登录页组件
|
|
import NotFound from '@/views/404'; // 404 页面组件
|
|
|
|
// 动态导入后台菜单相关的模块列表组件(使用 Velocity 模板循环生成)
|
|
#foreach($tableName in $backMenuTables)
|
|
import ${tableName} from '@/views/modules/${tableName}/list'
|
|
#end
|
|
|
|
// 2. 配置路由规则
|
|
const routes = [
|
|
{
|
|
path: '/index', name:'index', component: Index, children: [
|
|
// 默认子路由:访问 /index 自动跳转到首页
|
|
{
|
|
path: '/',
|
|
name: 'home',
|
|
component: Home
|
|
},
|
|
// 动态生成后台菜单对应的路由(每个表一个路由)
|
|
#foreach($tableName in $backMenuTables)
|
|
,{
|
|
path: '/${tableName}',
|
|
name: '${tableName}',
|
|
component: ${tableName}
|
|
}
|
|
#end
|
|
]
|
|
},
|
|
// 登录页路由
|
|
{ path: '/login', name:'login', component: Login },
|
|
// 默认跳转至首页
|
|
{ path: '/', redirect: '/index/' },
|
|
// 所有未匹配路径都跳转到 404 页面
|
|
{ path: '*', component: NotFound }
|
|
];
|
|
|
|
// 3. 实例化 VueRouter 路由对象
|
|
const router = new VueRouter({
|
|
mode: 'hash', /* 使用 hash 模式,也可改为 history 模式 */
|
|
routes /* 简写形式,相当于 routes: routes */
|
|
})
|
|
|
|
// 导出路由实例,供 main.js 使用
|
|
export default router;
|