diff --git a/packages/uni-h5/src/framework/setup/index.ts b/packages/uni-h5/src/framework/setup/index.ts index 2e29b7e1d29b182d13ff9fb91ac842d82223f240..1b7c0f551c5b6c952aa2c91be032b8f7440d0188 100644 --- a/packages/uni-h5/src/framework/setup/index.ts +++ b/packages/uni-h5/src/framework/setup/index.ts @@ -157,7 +157,7 @@ export function setupApp(comp: any) { } const onLaunch = () => { injectAppHooks(instance) - const { onLaunch, onShow, onPageNotFound } = instance + const { onLaunch, onShow, onPageNotFound, onError } = instance const path = route.path.slice(1) const launchOptions = initLaunchOptions({ path: path || __uniRoutes[0].meta.route, @@ -178,6 +178,11 @@ export function setupApp(comp: any) { invokeArrayFns(onPageNotFound, pageNotFoundOptions) } } + if (onError) { + instance.appContext.config.errorHandler = (err) => { + invokeArrayFns(onError, err) + } + } } if (__UNI_FEATURE_PAGES__) { // 等待ready后,再onLaunch,否则直达非首页无法获取到正确的path和query