fix: prefer H5 pathname for route guard

This commit is contained in:
Codex
2026-07-02 02:06:47 +08:00
parent b0e08acd8d
commit 60b1cb227c

View File

@@ -24,14 +24,13 @@ function forbiddenUrl(reason: string, redirectPath: string) {
} }
export function currentPagePath() { 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') { if (isH5Runtime() && typeof window !== 'undefined') {
const pathname = window.location.pathname || ''; const pathname = window.location.pathname || '';
if (pathname.startsWith('/pages/')) return pathname; if (pathname.startsWith('/pages/')) return pathname;
} }
const instance = Taro.getCurrentInstance();
const path = instance.router?.path || '';
const normalizedPath = path.startsWith('/') ? path : `/${path}`;
return normalizedPath; return normalizedPath;
} }