element/examples/route.config.js

83 lines
1.7 KiB
JavaScript
Raw Normal View History

2016-07-27 14:15:02 +08:00
import navConfig from './nav.config.json';
const registerRoute = (config) => {
2016-08-22 17:49:20 +08:00
let route = [{
path: '/component',
component: require('./pages/component.vue'),
children: []
}];
2016-08-23 17:39:58 +08:00
function addRoute(page) {
const component = require(`./docs${page.path}.md`);
2016-07-27 17:05:28 +08:00
2016-08-23 17:39:58 +08:00
route[0].children.push({
path: page.path.slice(1),
meta: {
title: page.title || page.name,
description: page.description
},
component: component.default || component
});
}
config
.map(nav => {
if (nav.groups) {
nav.groups.map(group => {
group.list.map(page => {
addRoute(page);
2016-08-23 19:15:15 +08:00
});
2016-08-23 17:39:58 +08:00
});
}
if (nav.children) {
nav.children.map(page => {
addRoute(page);
2016-07-27 17:05:28 +08:00
});
2016-08-23 17:39:58 +08:00
}
});
2016-07-27 14:15:02 +08:00
return { route, navs: config };
};
const route = registerRoute(navConfig);
2016-08-22 17:49:20 +08:00
let guideRoute = {
path: '/guide',
name: '指南',
component: require('./pages/guide.vue'),
children: [{
path: 'design',
name: '设计原则',
component: require('./pages/design.vue')
}, {
path: 'nav',
name: '导航',
component: require('./pages/nav.vue')
}]
};
let resourceRoute = {
path: '/resource',
name: '资源',
component: require('./pages/resource.vue')
};
2016-08-23 17:39:58 +08:00
let indexRoute = {
path: '/',
name: '首页',
component: require('./pages/index.vue')
};
2016-08-22 17:49:20 +08:00
let changeLogRoute = {
2016-07-27 17:05:28 +08:00
path: '/changelog',
2016-08-22 17:49:20 +08:00
component: require('./pages/changelog.vue')
};
2016-08-23 17:39:58 +08:00
route.route = route.route.concat([indexRoute, guideRoute, resourceRoute, changeLogRoute]);
2016-07-27 14:15:02 +08:00
2016-07-27 17:05:28 +08:00
route.route.push({
path: '*',
component: require('./docs/home.md')
});
export const navs = route.navs;
export default route.route;