-
Notifications
You must be signed in to change notification settings - Fork 127
/
Copy pathindex.ts
41 lines (37 loc) · 1016 Bytes
/
index.ts
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
import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'
import Home from '../views/Home.vue'
/** 自动加载其他路由模块 */
const files = require.context('.', true, /\.ts$/)
const modules: Array<RouteRecordRaw> = []
files.keys().forEach((key) => {
if (key === './index.ts') return
modules.push(files(key).default)
})
const routes: Array<RouteRecordRaw> = [
{
path: '/',
name: 'Home',
component: Home
},
...modules,
{
path: '/contact',
name: 'Contact',
// route level code-splitting
// this generates a separate chunk (about.[hash].js) for this route
// which is lazy-loaded when the route is visited.
component: () =>
import(/* webpackChunkName: "contact" */ '../views/Contact.vue')
},
{
path: '/tests',
name: 'Tests',
component: () =>
import(/* webpackChunkName: "Test" */ '../views/test/Test.vue')
}
]
const router = createRouter({
history: createWebHashHistory(),
routes
})
export default router