element/examples/route.config.js

82 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',
2016-09-14 11:15:28 +08:00
redirect: '/component/quickstart',
2016-08-22 17:49:20 +08:00
component: require('./pages/component.vue'),
2016-09-08 18:11:18 +08:00
children: []
2016-08-22 17:49:20 +08:00
}];
2016-08-23 17:39:58 +08:00
function addRoute(page) {
2016-09-29 12:11:54 +08:00
const component = page.path === '/changelog' ? require('./pages/changelog.vue') : require(`./docs/zh-cn${page.path}.md`);
2016-09-14 11:15:28 +08:00
let child = {
2016-08-23 17:39:58 +08:00
path: page.path.slice(1),
meta: {
title: page.title || page.name,
2016-09-08 18:11:18 +08:00
description: page.description
2016-08-23 17:39:58 +08:00
},
component: component.default || component
2016-09-14 11:15:28 +08:00
};
route[0].children.push(child);
2016-08-23 17:39:58 +08:00
}
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
});
2016-09-14 11:15:28 +08:00
} else if (nav.children) {
2016-08-23 17:39:58 +08:00
nav.children.map(page => {
addRoute(page);
2016-07-27 17:05:28 +08:00
});
2016-09-14 11:15:28 +08:00
} else {
addRoute(nav);
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: '指南',
2016-09-14 11:15:28 +08:00
redirect: '/guide/design',
2016-08-22 17:49:20 +08:00
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-09-14 18:38:38 +08:00
route.route = route.route.concat([indexRoute, guideRoute, resourceRoute]);
2016-07-27 14:15:02 +08:00
2016-07-27 17:05:28 +08:00
route.route.push({
path: '*',
2016-09-29 12:11:54 +08:00
component: require('./docs/zh-cn/home.md')
2016-07-27 17:05:28 +08:00
});
export const navs = route.navs;
export default route.route;