diff --git a/app/src/ui/client/BkndProvider.tsx b/app/src/ui/client/BkndProvider.tsx index 4e938d1..113ec73 100644 --- a/app/src/ui/client/BkndProvider.tsx +++ b/app/src/ui/client/BkndProvider.tsx @@ -9,7 +9,7 @@ import { Message } from "ui/components/display/Message"; import { useNavigate } from "ui/lib/routes"; export type BkndAdminOptions = { - basepath?: string; + admin_basepath?: string; logo_return_path?: string; theme?: AppTheme; }; @@ -169,7 +169,7 @@ export function useBkndOptions(): BkndAdminOptions { const ctx = useContext(BkndContext); return ( ctx.options ?? { - basepath: "/", + admin_basepath: "/", } ); } diff --git a/app/src/ui/client/utils/AppReduced.ts b/app/src/ui/client/utils/AppReduced.ts index 4da7b0d..f7eb603 100644 --- a/app/src/ui/client/utils/AppReduced.ts +++ b/app/src/ui/client/utils/AppReduced.ts @@ -6,6 +6,23 @@ import type { BkndAdminOptions } from "ui/client/BkndProvider"; export type AppType = ReturnType; +/** + * Normalize admin path by removing duplicate slashes and ensuring proper format + * @param path - The path to normalize + * @returns Normalized path + * @private + */ +function normalizeAdminPath(path: string): string { + // Remove duplicate slashes + const normalized = path.replace(/\/+/g, "/"); + // Don't remove trailing slash if it's the only character or if path ends with entity/ + if (normalized === "/" || normalized.endsWith("/entity/")) { + return normalized; + } + // Remove trailing slash for other paths + return normalized.replace(/\/$/, "") || "/"; +} + /** * Reduced version of the App class for frontend use * @todo: remove this class @@ -68,20 +85,19 @@ export class AppReduced { get options() { return { - basepath: "", + admin_basepath: "", logo_return_path: "/", ...this._options, }; } getSettingsPath(path: string[] = []): string { - const base = `~/${this.options.basepath}/settings`.replace(/\/+/g, "/"); - return [base, ...path].join("/"); + const base = `~/${this.options.admin_basepath}/settings` + return normalizeAdminPath([base, ...path].join("/")); } getAbsolutePath(path?: string): string { - const { basepath } = this.options; - return (path ? `~/${basepath}/${path}` : `~/${basepath}`).replace(/\/+/g, "/"); + return normalizeAdminPath((path ? `~/${this.options.admin_basepath}/${path}` : `~/${this.options.admin_basepath}`)); } getAuthConfig() {