Files
dukang/packages/weixin-sdk/src/app-path.ts
T
jacy eb961c3a74 feat(h5): unify WeChat OAuth under m.runxian.top path routing
Serve user/shop/partner H5 under /user/, /shop/, /partner/ on a single authorized domain; update nginx, SSL script, and router base paths.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-07 22:07:47 +08:00

26 lines
978 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/// <reference types="vite/client" />
function normalizeBase(base?: string): string {
if (!base || base === '/') return '';
return base.replace(/\/$/, '');
}
/** React Router basename(来自 Vite `base` */
export function getRouterBasename(baseUrl?: string): string | undefined {
const base = normalizeBase(baseUrl ?? import.meta.env?.BASE_URL);
return base || undefined;
}
/** 拼接带 Vite base 前缀的应用内路径(用于 window.location 跳转) */
export function toAppPath(path: string, baseUrl?: string): string {
const base = normalizeBase(baseUrl ?? import.meta.env?.BASE_URL);
const normalized = path.startsWith('/') ? path : `/${path}`;
return `${base}${normalized}`;
}
export function isOnAppPath(path: string, baseUrl?: string): boolean {
if (typeof window === 'undefined') return false;
const target = toAppPath(path, baseUrl);
return window.location.pathname === target || window.location.pathname.startsWith(`${target}/`);
}