1 | import _demoList from '.demoList.json';
|
2 | import Vue from 'vue/dist/vue.esm';
|
3 | import VueRouter from 'vue-router';
|
4 | import bus from '@/js/eventbus.js';
|
5 |
|
6 | import VesselPage from '@/pages/vessel.vue';
|
7 | import NotFoundPage from '@/pages/notFound.vue'
|
8 |
|
9 | Vue.use(VueRouter);
|
10 |
|
11 | const demoList = _demoList.map((demo) => {
|
12 | if(typeof demo !== 'string') return demo.src;
|
13 | return demo;
|
14 | });
|
15 |
|
16 | const demoRoutes = demoList.map(demoName => ({
|
17 | name: demoName,
|
18 | path: `/${demoName}`,
|
19 | component: VesselPage,
|
20 | }));
|
21 |
|
22 | const defaultRoute = {
|
23 | path: '/',
|
24 | redirect: { name: demoList[0] },
|
25 | }
|
26 |
|
27 |
|
28 | const nfpRoute = {
|
29 | path: '/404',
|
30 | component: NotFoundPage,
|
31 | }
|
32 |
|
33 | const unexistRouter = {
|
34 | path: '*',
|
35 | component: NotFoundPage,
|
36 | }
|
37 |
|
38 | const routes = [
|
39 | defaultRoute,
|
40 | ...demoRoutes,
|
41 | nfpRoute,
|
42 | unexistRouter,
|
43 | ];
|
44 |
|
45 |
|
46 | const router = new VueRouter({
|
47 | routes,
|
48 | });
|
49 |
|
50 | router.beforeEach((to, from, next) => {
|
51 | if(to.name && demoList.indexOf(to.name) > -1) {
|
52 | bus.$emit('setBoxes', to.name);
|
53 | } else if(to.name) {
|
54 | router.push({path: '/404'});
|
55 | }
|
56 | next();
|
57 | });
|
58 |
|
59 | window.router = router;
|
60 | export default router; |
\ | No newline at end of file |