一.添加动态路由
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");
这个方法也可以删除普通的路由