feat: menu routing support opens in a new window (#4715)

This commit is contained in:
Vben
2024-10-22 22:24:56 +08:00
committed by GitHub
parent f60796f961
commit 23768ea620
13 changed files with 315 additions and 190 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,