This commit is contained in:
dap
2024-10-23 07:49:10 +08:00
13 changed files with 95 additions and 28 deletions

View File

@@ -1,23 +1,25 @@
import { useRouter } from 'vue-router';
import { type RouteRecordNormalized, useRouter } from 'vue-router';
import { isHttpUrl, openWindow } from '@vben/utils';
import { isHttpUrl, openRouteInNewWindow, openWindow } from '@vben/utils';
function useNavigation() {
const router = useRouter();
const routes = router.getRoutes();
const routeMetaMap = new Map<string, any>();
const routeMetaMap = new Map<string, RouteRecordNormalized>();
routes.forEach((route) => {
routeMetaMap.set(route.path, route.meta);
routeMetaMap.set(route.path, route);
});
const navigation = async (path: string) => {
const route = routeMetaMap.get(path);
const { openInNewWindow = false, query = {} } = route?.meta ?? {};
if (isHttpUrl(path)) {
openWindow(path, { target: '_blank' });
} else if (openInNewWindow) {
openRouteInNewWindow(path);
} else {
const meta = routeMetaMap.get(path);
const query = meta?.query ?? {};
await router.push({
path,
query,