diff --git a/packages/uni-h5/src/service/api/route/utils.ts b/packages/uni-h5/src/service/api/route/utils.ts index dd6705ccd1..3550739aa1 100644 --- a/packages/uni-h5/src/service/api/route/utils.ts +++ b/packages/uni-h5/src/service/api/route/utils.ts @@ -1,5 +1,7 @@ -import { EventChannel, parseUrl } from '@dcloudio/uni-shared' +import { EventChannel, ON_PAGE_NOT_FOUND, parseUrl } from '@dcloudio/uni-shared' import { type Router, isNavigationFailure } from 'vue-router' +import type { ComponentPublicInstance } from 'vue' +import { invokeHook } from '@dcloudio/uni-core' import { createPageState, entryPageState, @@ -49,6 +51,20 @@ export function navigate( if (isNavigationFailure(failure)) { return reject(failure.message) } + if (router.currentRoute.value.matched.length === 0) { + invokeHook( + (__X__ ? (getApp() as any).vm : getApp()) as ComponentPublicInstance, + ON_PAGE_NOT_FOUND, + { + notFound: true, + openType: type, + path, + query, + scene: 1001, + } + ) + return reject(`page '${path}' is not found`) + } if (type === 'switchTab') { router.currentRoute.value.meta.tabBarText = tabBarText }