forked from youzan/vant
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrouter.config.js
More file actions
71 lines (62 loc) · 1.65 KB
/
router.config.js
File metadata and controls
71 lines (62 loc) · 1.65 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import docConfig from './doc.config';
import DemoList from './components/DemoList';
import componentDocs from '../markdown';
import componentDemos from '../demos';
import DemoPages from './components/DemoPages';
import Vue from 'vue';
import './utils/iframe-router';
const registerRoute = (isExample) => {
const route = [{
path: '*',
redirect: to => `/${Vue.prototype.$vantLang}/`
}];
Object.keys(docConfig).forEach((lang, index) => {
if (isExample) {
route.push({
path: `/${lang}`,
component: DemoList,
meta: { lang }
});
} else {
route.push({
path: `/${lang}`,
redirect: `/${lang}/component/intro`
});
}
const navs = docConfig[lang].nav || [];
navs.forEach(nav => {
if (isExample && !nav.showInMobile) {
return;
}
if (nav.groups) {
nav.groups.forEach(group => {
group.list.forEach(page => addRoute(page, lang));
});
} else if (nav.children) {
nav.children.forEach(page => addRoute(page, lang));
} else {
addRoute(nav, lang);
}
});
function addRoute(page, lang) {
const { path } = page;
if (path) {
const name = lang + '/' + path.replace('/', '');
let component;
if (path === '/demo') {
component = DemoPages;
} else {
component = isExample ? componentDemos[path.replace('/', '')] : componentDocs[name];
}
route.push({
name,
component,
path: `/${lang}/component${path}`,
meta: { lang }
});
}
}
});
return route;
};
export default registerRoute;