From 60b1cb227c9710e45fd39c37edc558b03b559509 Mon Sep 17 00:00:00 2001 From: Codex Date: Thu, 2 Jul 2026 02:06:47 +0800 Subject: [PATCH] fix: prefer H5 pathname for route guard --- apps/taro/src/services/routeGuard.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/apps/taro/src/services/routeGuard.ts b/apps/taro/src/services/routeGuard.ts index 889d33dc..863aa168 100644 --- a/apps/taro/src/services/routeGuard.ts +++ b/apps/taro/src/services/routeGuard.ts @@ -24,14 +24,13 @@ function forbiddenUrl(reason: string, redirectPath: string) { } export function currentPagePath() { - const instance = Taro.getCurrentInstance(); - const path = instance.router?.path || ''; - const normalizedPath = path.startsWith('/') ? path : `/${path}`; - if (normalizedPath !== '/') return normalizedPath; if (isH5Runtime() && typeof window !== 'undefined') { const pathname = window.location.pathname || ''; if (pathname.startsWith('/pages/')) return pathname; } + const instance = Taro.getCurrentInstance(); + const path = instance.router?.path || ''; + const normalizedPath = path.startsWith('/') ? path : `/${path}`; return normalizedPath; }