调整框架导航处理动态路由时的问题
This commit is contained in:
parent
369fdaf825
commit
51c170acf8
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue