|
1 | | -import Vue from 'vue' |
2 | | -import VueRouter from 'vue-router' |
3 | | - |
4 | | -/** |
5 | | - * 官方 component: () => import('../views/login/Login') |
6 | | - * webpack懒加载 component: r => require.ensure([], () => r(require('../views/login/Login')), 'Login'), |
7 | | - * import加载所有 import Login from '../views/login/Login' |
8 | | - */ |
9 | | - |
10 | | -Vue.use(VueRouter) |
| 1 | +import Vue from "vue"; |
| 2 | +import VueRouter from "vue-router"; |
| 3 | +import Home from "../views/Home.vue"; |
| 4 | +Vue.use(VueRouter); |
11 | 5 |
|
12 | 6 | const routes = [ |
13 | 7 | { |
14 | | - path: '/', |
15 | | - name: 'login', |
16 | | - component: () => import('../views/login/Login'), |
| 8 | + path: "*", //输错路由回首页 |
| 9 | + redirect: "/404", |
| 10 | + hidden: true, |
17 | 11 | meta: { |
| 12 | +title: "输错路由回首页", |
18 | 13 | keepAlive: false, |
19 | | - title: '登录' |
| 14 | + level: 0 //判断是否缓存 0为不缓存 1为缓存 2为详情页 |
20 | 15 | } |
21 | 16 | }, |
22 | 17 | { |
23 | | - path: '*',//输错路由前往404 |
24 | | - redirect: '/404', |
| 18 | + path: "/", //默认路由 |
| 19 | + redirect: "/login", |
| 20 | + hidden: true, |
25 | 21 | meta: { |
| 22 | +title: "默认路由", |
26 | 23 | keepAlive: false, |
27 | | - title: '404' |
| 24 | + level: 0 |
28 | 25 | } |
29 | 26 | }, |
| 27 | + //登录 |
30 | 28 | { |
31 | | - path: '/404', |
32 | | - name: 'notFound', |
33 | | - component: () => import('../views/error/NotFound'), |
| 29 | + path: "/login", |
| 30 | + name: "login", |
| 31 | + component: r => require.ensure([], () => r(require("../views/login/Login.vue")), "Login"), |
| 32 | + hidden: true, |
34 | 33 | meta: { |
| 34 | +title: "登录", |
35 | 35 | keepAlive: false, |
36 | | - title: '404' |
| 36 | + level: 0 |
37 | 37 | } |
38 | 38 | }, |
| 39 | + //404 |
39 | 40 | { |
40 | | - path: '/home', |
41 | | - name: 'home', |
42 | | - redirect: '/summary', |
43 | | - component: () => import('../views/home/Index'), |
| 41 | + path: "/404", |
| 42 | + name: "notFound", |
| 43 | + component: r => require.ensure([], () => r(require("../views/error/NotFound.vue")), "NotFound"), |
| 44 | + hidden: true, |
44 | 45 | meta: { |
| 46 | +title: "404", |
45 | 47 | keepAlive: false, |
46 | | - title: '首页' |
47 | | - }, |
| 48 | + level: 0 |
| 49 | + } |
| 50 | + }, |
| 51 | + { |
| 52 | + path: "/home", |
| 53 | + name: "home", |
| 54 | + component: Home, |
| 55 | + redirect: '/summarys/index', |
| 56 | + hidden: true, |
| 57 | + meta: { |
| 58 | +title: "首页", |
| 59 | + keepAlive: false, |
| 60 | + level: 0 |
| 61 | + } |
| 62 | + }, |
| 63 | + { |
| 64 | + path: "/summarys", |
| 65 | + component: Home, |
| 66 | + iconCls: "fa el-icon-s-data", |
| 67 | +hidden: false, |
| 68 | +meta: { |
| 69 | +title: "简介", |
| 70 | + keepAlive: false, |
| 71 | + level: 0 |
| 72 | +}, |
48 | 73 | children: [ |
49 | 74 | { |
50 | | - path: '/summary', |
51 | | - name: 'summary', |
52 | | - // route level code-splitting |
53 | | - // this generates a separate chunk (about.[hash].js) for this route |
54 | | - // which is lazy-loaded when the route is visited. |
55 | | - component: () => import('../views/Summary'), |
56 | | - meta: {//缓存、路由元信息、元字段 |
57 | | - keepAlive: false, |
58 | | - title: '概述', |
59 | | - //requiresAuth: true |
60 | | - } |
61 | | - }, |
62 | | - { |
63 | | - path: '/doc', |
64 | | - name: 'doc', |
65 | | - component: () => import('../views/Doc'), |
| 75 | + path: "/summarys/index", |
| 76 | + component: () => import("../views/summarys/index.vue"), |
| 77 | + name: "summarys", |
| 78 | +hidden: false, |
66 | 79 | meta: { |
67 | | - keepAlive: false, |
68 | | - title: '文档' |
| 80 | +title: "简介首页", |
| 81 | +keepAlive: false, |
| 82 | +level: 0 |
69 | 83 | } |
70 | 84 | }, |
71 | 85 | { |
72 | | - path: '/good-list', |
73 | | - name: 'goodList', |
74 | | - component: () => import('../views/good-list/GoodList'), |
| 86 | + path: "/goods/goodsList", |
| 87 | + component: () => import("../views/goods/goodsList.vue"), |
| 88 | + name: "goodsList", |
| 89 | +hidden: false, |
75 | 90 | meta: { |
76 | | - keepAlive: false, |
77 | | - title: '商品列表' |
78 | | - }, |
79 | | - children: [] |
| 91 | +title: "商品列表", |
| 92 | +keepAlive: false, |
| 93 | +level: 0 |
| 94 | + } |
80 | 95 | }, |
81 | 96 | { |
82 | | - path: '/good-list/good-detail', |
83 | | - name: 'goodDetail', |
84 | | - component: () => import('../views/good-list/GoodDetail'), |
| 97 | + path: "/goods/goodsList/goodsDetail", |
| 98 | + component: () => import("../views/goods/goodsDetail.vue"), |
| 99 | + name: "goodsDetail", |
| 100 | +hidden: true, |
85 | 101 | meta: { |
86 | | - keepAlive: false, |
87 | | - title: '商品详情', |
88 | | - parentPath: '/good-list', |
89 | | - parentTitle: '商品列表' |
| 102 | +title: "商品列表", |
| 103 | +parentPath: "/goods/goodsList", |
| 104 | +parentTitle: "商品列表", |
| 105 | +keepAlive: false, |
| 106 | +level: 0 |
90 | 107 | } |
91 | 108 | } |
92 | 109 | ] |
93 | 110 | } |
94 | 111 | ] |
95 | 112 |
|
96 | 113 | const router = new VueRouter({ |
97 | | - // mode: 'history', |
| 114 | + mode: "history", |
98 | 115 | base: process.env.BASE_URL, |
99 | 116 | routes |
100 | | -}) |
101 | | -export default router |
| 117 | +}); |
| 118 | + |
| 119 | +//全局路由守卫、路由拦截 |
| 120 | +// router.beforeEach((to, from, next) => { |
| 121 | +// const isLogin = localStorage.token ? true : false; |
| 122 | +// if (to.path === "/login" || to.path === "/forgotPassword") { |
| 123 | +// next(); |
| 124 | +// } else { |
| 125 | +// isLogin ? next() : next("/"); |
| 126 | +// } |
| 127 | +// }); |
| 128 | + |
| 129 | +export default router; |
0 commit comments