Skip to content

Fix(UI): correct dashboard URLs when mounted at root#44

Merged
igorbenav merged 2 commits intobenavlabs:mainfrom
andriialbatov:fix/mounting-on-slash-dashboard
Jun 26, 2025
Merged

Fix(UI): correct dashboard URLs when mounted at root#44
igorbenav merged 2 commits intobenavlabs:mainfrom
andriialbatov:fix/mounting-on-slash-dashboard

Conversation

@andriialbatov
Copy link
Copy Markdown
Contributor

🐛 Problem

When mounting the admin panel at the root path (mount_path="/"), dashboard content fails to load. The issue comes from templates building URLs like:

<a href="/{{ mount_path }}/...">

With an empty mount_path, this results in //dashboard-content, which doesn’t match any registered FastAPI route.

✅ Solution

To fix this, I introduced a url_prefix variable in the Python context that normalizes the mount path with a leading slash only when necessary:

self.url_prefix = f"/{self.mount_path}" if self.mount_path else ""

All template links now use {{ url_prefix }} instead of building paths manually:

<a href="{{ url_prefix }}/">Link</a>

This ensures routes work whether the panel is mounted at /, /admin, or any subpath.

🧪 Testing

  • mount_path="/" → dashboard loads ✅
  • mount_path="/admin" → still works as before ✅
  • Verified dashboard content, navigation links, HTMX loading

📹 Before Fix

Screen.Recording.2025-06-25.at.1.54.20.PM.mov

@igorbenav igorbenav added the bug Something isn't working label Jun 25, 2025
@igorbenav
Copy link
Copy Markdown
Collaborator

Nice one, @andriialbatov! Just fix linting and I'll merge it

@igorbenav igorbenav merged commit e7dfe4d into benavlabs:main Jun 26, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants