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; }