feat: 路由参数
This commit is contained in:
@@ -10,6 +10,7 @@ import {
|
||||
generateRoutesByBackend,
|
||||
generateRoutesByFrontend,
|
||||
mapTree,
|
||||
setObjToUrlParams,
|
||||
} from '@vben/utils';
|
||||
|
||||
async function generateAccessible(
|
||||
@@ -82,7 +83,14 @@ async function generateRoutes(
|
||||
return route;
|
||||
}
|
||||
|
||||
route.redirect = firstChild.path;
|
||||
// 第一个路由如果有query参数 需要加上参数
|
||||
const fistChildQuery = route.children[0]?.meta?.query;
|
||||
// 根目录菜单固定只有一个children 且path为/ 不需要添加redirect
|
||||
route.redirect =
|
||||
fistChildQuery && route.children.length !== 1 && route.path !== '/'
|
||||
? setObjToUrlParams(firstChild.path, fistChildQuery)
|
||||
: firstChild.path;
|
||||
|
||||
return route;
|
||||
});
|
||||
|
||||
|
@@ -1,14 +1,21 @@
|
||||
import { useRouter } from 'vue-router';
|
||||
|
||||
import { isHttpUrl, openWindow } from '@vben/utils';
|
||||
import { isHttpUrl, isObject, openWindow } from '@vben/utils';
|
||||
|
||||
function useNavigation() {
|
||||
const router = useRouter();
|
||||
const allRoutes = router.getRoutes();
|
||||
|
||||
const navigation = async (path: string) => {
|
||||
if (isHttpUrl(path)) {
|
||||
openWindow(path, { target: '_blank' });
|
||||
} else {
|
||||
// 带路由参数
|
||||
const found = allRoutes.find((item) => item.path === path);
|
||||
if (found && isObject(found.meta.query)) {
|
||||
await router.push({ path, query: found.meta.query });
|
||||
return;
|
||||
}
|
||||
await router.push(path);
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user