forked from bookpauk/inpx-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
router.js
42 lines (34 loc) · 1007 Bytes
/
router.js
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
import { createRouter, createWebHashHistory } from 'vue-router';
import _ from 'lodash';
const Search = () => import('./components/Search/Search.vue');
const myRoutes = [
['/', Search],
['/author', Search],
['/series', Search],
['/title', Search],
['/extended', Search],
['/:pathMatch(.*)*', null, null, '/'],
];
let routes = {};
for (let route of myRoutes) {
const [path, component, name, redirect] = route;
let cleanRoute = _.pickBy({path, component, name, redirect}, _.identity);
let parts = cleanRoute.path.split('~');
let f = routes;
for (let part of parts) {
const curRoute = _.assign({}, cleanRoute, { path: part });
if (!f.children)
f.children = [];
let r = f.children;
f = _.find(r, {path: part});
if (!f) {
r.push(curRoute);
f = curRoute;
}
}
}
routes = routes.children;
export default createRouter({
history: createWebHashHistory(),
routes
});