vue3 vite动态路由的问题

因为to.matched未配到路由导致,

vue-router.mjs:35 [Vue Router warn]: No match found for location with path "/basedata/psiIntialCustomer/add"

加下面的代码,是解决不了问题,因为它只是转向了404页面。

const routes_404 = {
   
	path: "/:pathMatch(.*)*",
	hidden: true,
	component: () => import('@/layout/other/404.vue'),
}

客户期初余额新增、编辑无法跳转,但是最有一个供应商期初余额却可以,甚是奇怪。
1
今天调试发现tomatch为空,是因为matchMap中key有相同的名字。菜单名称不重复,问题就解决了。
1
下面是动态路由的主要代码,这里不要用eager,因为那个是同步的。很多地方会出错。因此按照下方编写即可。

// 加载所有得页面
const modules = import.meta.glob('@/views/**/*.vue');

//转换
function filterAsyncRouter(routerMap) {
   
	const accessedRouters = []
	routerMap.forEach(item => {
   
		item.meta = item.meta?item.meta:{
   };
		//处理外部链接特殊路由
		if(item.meta.type=='iframe'){
   
			item.meta.url = item.path;
			item.path = `/i/${
     item.name}`;
		}
		//MAP转路由对象
		var route = {
   
			path: item.url,
			name: item.name,
			meta: item.meta,
			redirect: item.redirect,
			children: item.children ? filterAsyncRouter(item.children) : null,
			component: loadComponent(item.url)
		}
		accessedRouters.push(route)
	})
	return accessedRouters
}
function loadComponent(component){
   
	let res;
	if (component){
   
		for (const path in modules) {
   
			const dir = path.split('views')[1].split('.vue')[0];
			if (dir.indexOf(component)>-1) {
   
				res = () => modules[path]();
				break;
			}
		}
	} else{
   
		res =() => import(`@/layout/other/empty.vue`)
	}
    return res;

}```

相关推荐

  1. vue3+vite动态实现方式

    2023-12-17 00:48:02       66 阅读
  2. vue3+vite+ts+pinia+router4后台管理-动态生成

    2023-12-17 00:48:02       20 阅读
  3. vue3之带参数动态

    2023-12-17 00:48:02       45 阅读
  4. Vue3-40-- 动态

    2023-12-17 00:48:02       48 阅读
  5. vue3如何实现动态

    2023-12-17 00:48:02       67 阅读
  6. vue3动态

    2023-12-17 00:48:02       36 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2023-12-17 00:48:02       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2023-12-17 00:48:02       101 阅读
  3. 在Django里面运行非项目文件

    2023-12-17 00:48:02       82 阅读
  4. Python语言-面向对象

    2023-12-17 00:48:02       91 阅读

热门阅读

  1. 前端(二)

    2023-12-17 00:48:02       54 阅读
  2. 使用Python实现蒙特卡罗算法

    2023-12-17 00:48:02       54 阅读
  3. C#基础——面向对象(封装 继承 多态)

    2023-12-17 00:48:02       64 阅读
  4. ca-certificates.crt解析加载到nssdb中

    2023-12-17 00:48:02       55 阅读
  5. Go中的工作池:并发任务的优雅管理

    2023-12-17 00:48:02       52 阅读
  6. 快速学习C++中的模板

    2023-12-17 00:48:02       54 阅读
  7. [笔记] wsl2 下使用 qemu/grub 模拟系统启动(多分区)

    2023-12-17 00:48:02       56 阅读
  8. 来聊聊CAS

    2023-12-17 00:48:02       57 阅读
  9. Linux 中定时任务

    2023-12-17 00:48:02       56 阅读
  10. C语言第五十二弹--模拟使用strncat

    2023-12-17 00:48:02       49 阅读