mirror of
https://github.com/certd/certd.git
synced 2026-05-15 04:27:31 +08:00
335d175d57
chore: Merge branch 'vben' # Conflicts: # package.json perf: antdv示例改成使用vben框架 chore: vben chore: vben chore: vben
36 lines
868 B
TypeScript
36 lines
868 B
TypeScript
import type { RouteRecordNormalized } from "vue-router";
|
|
|
|
import { useRouter } from "vue-router";
|
|
|
|
import { isHttpUrl, openRouteInNewWindow, openWindow } from "../../../utils";
|
|
|
|
function useNavigation() {
|
|
const router = useRouter();
|
|
const routes = router.getRoutes();
|
|
|
|
const routeMetaMap = new Map<string, RouteRecordNormalized>();
|
|
|
|
routes.forEach((route) => {
|
|
routeMetaMap.set(route.path, route);
|
|
});
|
|
|
|
const navigation = async (path: string) => {
|
|
const route = routeMetaMap.get(path);
|
|
const { openInNewWindow = false, query = {} as any } = route?.meta ?? {};
|
|
if (isHttpUrl(path)) {
|
|
openWindow(path, { target: "_blank" });
|
|
} else if (openInNewWindow) {
|
|
openRouteInNewWindow(path);
|
|
} else {
|
|
await router.push({
|
|
path,
|
|
query
|
|
});
|
|
}
|
|
};
|
|
|
|
return { navigation };
|
|
}
|
|
|
|
export { useNavigation };
|