zhangwei
2025-06-18 19aef84d40fbe37b8ee49cdc14186261d8b928f5
src/router/utils.ts
@@ -120,14 +120,14 @@
/** 查找对应 `path` 的路由信息 */
function findRouteByPath(path: string, routes: RouteRecordRaw[]) {
  let res = routes.find((item: { path: string }) => item.path == path);
  let res = routes?.find((item: { path: string }) => item.path == path);
  if (res) {
    return isProxy(res) ? toRaw(res) : res;
  } else {
    for (let i = 0; i < routes.length; i++) {
    for (let i = 0; i < routes?.length; i++) {
      if (
        routes[i].children instanceof Array &&
        routes[i].children.length > 0
        routes[i]?.children instanceof Array &&
        routes[i]?.children.length > 0
      ) {
        res = findRouteByPath(path, routes[i].children);
        if (res) {
@@ -158,14 +158,14 @@
      (v: RouteRecordRaw) => {
        // 防止重复添加路由
        if (
          router.options.routes[0].children.findIndex(
          router.options.routes[0].children?.findIndex(
            value => value.path === v.path
          ) !== -1
        ) {
          return;
        } else {
          // 切记将路由push到routes后还需要使用addRoute,这样路由才能正常跳转
          router.options.routes[0].children.push(v);
          router.options.routes[0].children?.push(v);
          // 最终路由进行升序
          ascending(router.options.routes[0].children);
          if (!router.hasRoute(v?.name)) router.addRoute(v);