diff --git a/src/index-main.ts b/src/index-main.ts index f460c616..aaf77028 100644 --- a/src/index-main.ts +++ b/src/index-main.ts @@ -22,9 +22,9 @@ function isMobileDevice(): boolean { function navigate(type: string): void { if (__EZBOOKKEEPING_IS_PRODUCTION__) { - window.location.replace(`${type}/`); + window.location.replace(`${type}#/`); } else { - window.location.replace(`${type}.html`); + window.location.replace(`${type}.html#/`); } } diff --git a/src/lib/services.ts b/src/lib/services.ts index 29b706da..582b2677 100644 --- a/src/lib/services.ts +++ b/src/lib/services.ts @@ -133,6 +133,7 @@ import { } from './server_settings.ts'; import { getTimezoneOffsetMinutes } from './datetime.ts'; import { generateRandomUUID } from './misc.ts'; +import { getBasePath } from './web.ts'; interface ApiRequestConfig extends AxiosRequestConfig { readonly headers: AxiosRequestHeaders; @@ -147,7 +148,7 @@ export type ApiResponsePromise = Promise>>; let needBlockRequest = false; const blockedRequests: ((token: string | undefined) => void)[] = []; -axios.defaults.baseURL = BASE_API_URL_PATH; +axios.defaults.baseURL = getBasePath() + BASE_API_URL_PATH; axios.defaults.timeout = DEFAULT_API_TIMEOUT; axios.interceptors.request.use((config: ApiRequestConfig) => { const token = getCurrentToken(); @@ -560,11 +561,11 @@ export default { } as ApiRequestConfig); }, generateQrCodeUrl: (qrCodeName: string): string => { - return `${BASE_QRCODE_PATH}/${qrCodeName}.png`; + return `${getBasePath()}${BASE_QRCODE_PATH}/${qrCodeName}.png`; }, generateMapProxyTileImageUrl: (mapProvider: string, language: string): string => { const token = getCurrentToken(); - let url = `${BASE_PROXY_URL_PATH}/map/tile/{z}/{x}/{y}.png?provider=${mapProvider}&token=${token}`; + let url = `${getBasePath()}${BASE_PROXY_URL_PATH}/map/tile/{z}/{x}/{y}.png?provider=${mapProvider}&token=${token}`; if (language) { url = url + `&language=${language}`; @@ -574,7 +575,7 @@ export default { }, generateMapProxyAnnotationImageUrl: (mapProvider: string, language: string): string => { const token = getCurrentToken(); - let url = `${BASE_PROXY_URL_PATH}/map/annotation/{z}/{x}/{y}.png?provider=${mapProvider}&token=${token}`; + let url = `${getBasePath()}${BASE_PROXY_URL_PATH}/map/annotation/{z}/{x}/{y}.png?provider=${mapProvider}&token=${token}`; if (language) { url = url + `&language=${language}`; @@ -598,7 +599,7 @@ export default { return `${AMAP_JAVASCRIPT_URL}&key=${getAmapApplicationKey()}&plugin=AMap.ToolBar&callback=${callbackFnName}`; }, generateAmapApiInternalProxyUrl: (): string => { - return `${window.location.origin}${BASE_AMAP_API_PROXY_URL_PATH}`; + return `${window.location.origin}${getBasePath()}${BASE_AMAP_API_PROXY_URL_PATH}`; }, getInternalAvatarUrlWithToken(avatarUrl: string, disableBrowserCache?: boolean | string): string { if (!avatarUrl) { diff --git a/src/lib/version.ts b/src/lib/version.ts index 74f0c272..28b208a0 100644 --- a/src/lib/version.ts +++ b/src/lib/version.ts @@ -1,3 +1,5 @@ +import { getBasePath } from './web.ts'; + export function isProduction(): boolean { return __EZBOOKKEEPING_IS_PRODUCTION__; } @@ -28,15 +30,15 @@ export function getBuildTime(): string { export function getMobileVersionPath(): string { if (isProduction()) { - return '../mobile'; + return getBasePath() + '/mobile#/'; } else { - return 'mobile.html'; + return getBasePath() + '/mobile.html#/'; } } export function getDesktopVersionPath(): string { if (isProduction()) { - return '../desktop'; + return getBasePath() + '/desktop#/'; } else { - return 'desktop.html'; + return getBasePath() + '/desktop.html#/'; } } diff --git a/src/lib/web.ts b/src/lib/web.ts new file mode 100644 index 00000000..9ffda9f9 --- /dev/null +++ b/src/lib/web.ts @@ -0,0 +1,10 @@ +export function getBasePath(): string { + const path = window.location.pathname; + const lastSlashIndex = path.lastIndexOf('/'); + + if (lastSlashIndex < 0) { + return path; + } + + return path.substring(0, lastSlashIndex); +}