vant/docs/src/router.config.js
2017-08-09 16:21:16 +08:00

38 lines
846 B
JavaScript

const navs = require('./doc.config')['zh-CN'].nav;
import componentDocs from '../examples-dist/entry-docs';
import componentDemos from '../examples-dist/entry-demos';
const registerRoute = (isExample) => {
let route = [];
navs.forEach(nav => {
if (isExample && !nav.showInMobile) {
return;
}
if (nav.groups) {
nav.groups.forEach(group => {
group.list.forEach(addRoute);
});
} else if (nav.children) {
nav.children.forEach(addRoute);
} else {
addRoute(nav);
}
});
function addRoute(page) {
const { path } = page;
if (path) {
const name = path.replace('/', '');
route.push({
path: '/component' + path,
component: isExample ? componentDemos[name] : componentDocs[name]
});
}
}
return route;
};
export default registerRoute;