mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2025-04-06 03:58:05 +08:00
53 lines
924 B
JavaScript
53 lines
924 B
JavaScript
import docConfig from './doc.config';
|
|
|
|
const registerRoute = () => {
|
|
const route = [
|
|
{
|
|
path: '*',
|
|
redirect: () => `/intro`,
|
|
},
|
|
];
|
|
|
|
const navs = docConfig.nav || [];
|
|
|
|
function addRoute(page) {
|
|
let { path } = page;
|
|
if (path) {
|
|
path = path.replace('/', '');
|
|
|
|
const component = () =>
|
|
page.md
|
|
? import(`../markdown/${path}.md`)
|
|
: import(`../../packages/${path}/README.md`);
|
|
|
|
if (!component) {
|
|
return;
|
|
}
|
|
|
|
route.push({
|
|
name: '/' + path,
|
|
component,
|
|
path: `/${path}`,
|
|
meta: {
|
|
path,
|
|
name: page.title,
|
|
},
|
|
});
|
|
}
|
|
}
|
|
|
|
navs.forEach((nav) => {
|
|
if (nav.groups) {
|
|
nav.groups.forEach((group) => {
|
|
group.list.forEach((page) => addRoute(page));
|
|
});
|
|
} else {
|
|
addRoute(nav);
|
|
}
|
|
});
|
|
|
|
return route;
|
|
};
|
|
|
|
export default registerRoute;
|