013Vue3独立路由模块加载使用范例
- 通过路由懒加载,隔离辅助模块与主模块,也支持辅助模块独立调试与运行
子路由文件与模块map
export default [
{
path: '',
alias: '/about',
name: 'about',
component: () => import('@/views/test/about/Index.vue'),
meta: {
title: '关于我们',
},
},
{
path: 'props',
name: 'props',
component: () => import('@/views/test/props/Index.vue'),
meta: {
title: 'props测试',
},
},
];
主Vue3文件入口
- web-client\ui\src\views\test\Index.vue
<script setup lang="ts">
import IndexTest from './routes';
const menus = IndexTest.map((el: any) => {
return {
path: '/test/' + el.path,
title: el.meta.title || el.name || el.path,
};
});
</script>
<template>
<div>
<el-link type="primary" v-for="item in menus" :key="item.path" :href="item.path">
{{ item.title }}
</el-link>
</div>
<router-view></router-view>
</template>
<style scoped lang="scss">
.el-link {
margin-right: 8px;
}
</style>
独立路由模块挂载范例
import IndexTest from '@/views/test/Index.vue';
import testRoutes from '@/views/test/routes';
const routes: RouteRecordRaw[] = [
{
path: '/',
alias: '/index',
name: 'index',
component: IndexView,
meta: {
title: '主页',
},
children: [
{
path: '',
alias: 'ui',
name: 'ui',
component: () => import('@/views/ui/Index.vue'),
meta: {
title: 'UI主页',
},
},
],
},
{
path: '/test',
alias: '/t',
name: 'testIndex',
component: IndexTest,
meta: {
title: '测试',
},
children: [...testRoutes],
},
];