element/examples/route.config.js

89 lines
1.8 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'),
2016-08-31 11:25:02 +08:00
children: [],
scrollToTop: true
2016-08-22 17:49:20 +08:00
}];
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,
2016-08-31 11:25:02 +08:00
description: page.description,
scrollToTop: true
2016-08-23 17:39:58 +08:00
},
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'),
2016-08-31 11:25:02 +08:00
meta: { scrollToTop: true },
2016-08-22 17:49:20 +08:00
children: [{
path: 'design',
name: '设计原则',
component: require('./pages/design.vue')
}, {
path: 'nav',
name: '导航',
component: require('./pages/nav.vue')
}]
};
let resourceRoute = {
path: '/resource',
name: '资源',
2016-08-31 11:25:02 +08:00
meta: { scrollToTop: true },
2016-08-22 17:49:20 +08:00
component: require('./pages/resource.vue')
};
2016-08-23 17:39:58 +08:00
let indexRoute = {
path: '/',
name: '首页',
2016-08-31 11:25:02 +08:00
meta: { scrollToTop: true },
2016-08-23 17:39:58 +08:00
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-31 11:25:02 +08:00
meta: { scrollToTop: true },
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;