FIX: Handle href admin sidebar links better (#31575)

Admin sidebar links can have either a `href` or a
`route`, and the admin search was not handling
this properly. Also, we should always use `getURL()`
on the href in case the link is internal, for subfolder
sites.

This is hard to test right now, I plan on adding more extensive
links for admin-search-data-source in another PR.
This commit is contained in:
Martin Brennan 2025-03-04 13:38:49 +10:00 committed by GitHub
parent 879faa82b3
commit b329eac79a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 5 deletions

View File

@ -111,10 +111,14 @@ export default class AdminSearchDataSource extends Service {
#addPageLink(mapItem, link, parentLabel = "") {
let url;
if (link.routeModels) {
url = this.router.urlFor(link.route, ...link.routeModels);
} else {
url = this.router.urlFor(link.route);
if (link.route) {
if (link.routeModels) {
url = this.router.urlFor(link.route, ...link.routeModels);
} else {
url = this.router.urlFor(link.route);
}
} else if (link.href) {
url = getURL(link.href);
}
const mapItemLabel = this.#labelOrText(mapItem);

View File

@ -48,7 +48,9 @@ class SidebarAdminSectionLink extends BaseCustomSidebarSectionLink {
}
get href() {
return this.adminSidebarNavLink.href;
if (this.adminSidebarNavLink.href) {
return getURL(this.adminSidebarNavLink.href);
}
}
get query() {