路由优化

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import Vue from "vue";
import Router from "vue-router";
Vue.use(Router);

/**
* 简化router文件
* @param {[String]} path 定义路由路径
* @param {[String]} name 挂在文件路径
* @param {[String]} title 页面title
* @param {Object} [other={}] 路由其他参数
* @param {Array} [children=[]] 嵌套路由配置
* @return {Object} 返回router可用obj
*/
function path(path, name, title, other = {}, children = []) {
return Object.assign(
{
path: path,
name: name,
meta: {
title: title
},
component: resolve => require(["../pages/" + name + ".vue"], resolve),
children: children
},
other
);
}

let page = [];
// 测试页
page.push(
path("form", "test/form", "测试"),
path("table", "test/table", "acc")
);
// 流程管理
page.push(path("form", "process/list", ""));

export default new Router({
mode: "history",
routes: [
path("/", "index", "首页", { redirect: "/home/index" }),
path("/login", "public/login", "登录"),
//嵌套结构页
path("/home", "home", "", "", [
path("index", "public/home_index", ""), // 上下结构
path("aside", "public/aside", "", "", page) // 上左右结构
])
]
});