This repository was archived by the owner on Sep 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 102
/
Copy pathrouter.ts
47 lines (40 loc) · 2.04 KB
/
router.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
42
43
44
45
46
47
import Vue from 'vue'
import VueRouter, { Location, Route, RouteConfig } from 'vue-router'{{#hotReload}}
import { makeHot, reload } from './util/hot-reload'{{/hotReload}}
const homeComponent = () => import('./components/home').then(({ HomeComponent }) => HomeComponent)
const aboutComponent = () => import('./components/about').then(({ AboutComponent }) => AboutComponent)
const listComponent = () => import('./components/list').then(({ ListComponent }) => ListComponent)
// const homeComponent = () => import(/* webpackChunkName: 'home' */'./components/home').then(({ HomeComponent }) => HomeComponent)
// const aboutComponent = () => import(/* webpackChunkName: 'about' */'./components/about').then(({ AboutComponent }) => AboutComponent)
// const listComponent = () => import(/* webpackChunkName: 'list' */'./components/list').then(({ ListComponent }) => ListComponent)
{{#hotReload}}
if (process.env.ENV === 'development' && module.hot) {
const homeModuleId = './components/home'
const aboutModuleId = './components/about'
const listModuleId = './components/list'
// first arguments for `module.hot.accept` and `require` methods have to be static strings
// see https://github.com/webpack/webpack/issues/5668
makeHot(homeModuleId, homeComponent,
module.hot.accept('./components/home', () => reload(homeModuleId, (require('./components/home') as any).HomeComponent)))
makeHot(aboutModuleId, aboutComponent,
module.hot.accept('./components/about', () => reload(aboutModuleId, (require('./components/about') as any).AboutComponent)))
makeHot(listModuleId, listComponent,
module.hot.accept('./components/list', () => reload(listModuleId, (require('./components/list') as any).ListComponent)))
}
{{/hotReload}}
Vue.use(VueRouter)
export const createRoutes: () => RouteConfig[] = () => [
{
path: '/',
component: homeComponent
},
{
path: '/about',
component: aboutComponent
},
{
path: '/list',
component: listComponent
}
]
export const createRouter = () => new VueRouter({ mode: 'history', routes: createRoutes() })