调整框架导航处理动态路由时的问题

This commit is contained in:
z9130 2024-10-18 13:05:48 +08:00
parent 369fdaf825
commit 51c170acf8
1 changed files with 12 additions and 1 deletions

View File

@ -5,11 +5,22 @@ import { isHttpUrl, openWindow } from '@vben/utils';
function useNavigation() {
const router = useRouter();
// Helper function to clean up optional parameters
const cleanPath = (path: string) => {
// 正则匹配类似 :param? 的可选参数
return path.replace(/\/:\w+\?/g, '');
};
const navigation = async (path: string) => {
// 如果是HTTP URL则在新窗口打开
if (isHttpUrl(path)) {
openWindow(path, { target: '_blank' });
} else {
await router.push(path);
// 去除未赋值的可选参数
const cleanedPath = cleanPath(path);
// 路由跳转
await router.push(cleanedPath);
}
};