一.添加动态路由

1.引入 getCurrentInstance 这里需要使用 proxy代理

import { getCurrentInstance } from "vue";
const { proxy } = getCurrentInstance();

2.添加路由

// 使用 vite 创建的项目需要加上.vue
proxy.$router.addRoute({ path: "/path" name "PATH", component: () => import("@/views/path(.vue)") })

proxy.$router.push({ name: "PATH" })

二.删除路由

proxy.$router.removeRoute("PATH");

这个方法也可以删除普通的路由

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐