diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/menu/components/menu-item-layout/menu-item-layout.element.ts b/src/Umbraco.Web.UI.Client/src/packages/core/menu/components/menu-item-layout/menu-item-layout.element.ts index b6471e064d..c836c99aad 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/menu/components/menu-item-layout/menu-item-layout.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/menu/components/menu-item-layout/menu-item-layout.element.ts @@ -1,5 +1,6 @@ import { html, customElement, property, ifDefined, state } from '@umbraco-cms/backoffice/external/lit'; import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'; +import { ensureSlash } from '@umbraco-cms/backoffice/router'; import { debounce } from '@umbraco-cms/backoffice/utils'; /** @@ -62,8 +63,12 @@ export class UmbMenuItemLayoutElement extends UmbLitElement { return; } - const location = window.location.pathname; - this._isActive = location.includes(this.href); + /* Check if the current location includes the href of this menu item + We ensure that the paths ends with a slash to avoid collisions with paths like /path-1 and /path-1-2 where /path is in both. + Instead we compare /path-1/ with /path-1-2/ which wont collide.*/ + const location = ensureSlash(window.location.pathname); + const compareHref = ensureSlash(this.href); + this._isActive = location.includes(compareHref); } override render() { diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/tree/tree-item/tree-item-base/tree-item-context-base.ts b/src/Umbraco.Web.UI.Client/src/packages/core/tree/tree-item/tree-item-base/tree-item-context-base.ts index f80a8763fe..6ddd369c03 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/tree/tree-item/tree-item-base/tree-item-context-base.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/tree/tree-item/tree-item-base/tree-item-context-base.ts @@ -20,6 +20,7 @@ import type { UmbEntityActionEvent } from '@umbraco-cms/backoffice/entity-action import { UmbDeprecation, UmbPaginationManager, debounce } from '@umbraco-cms/backoffice/utils'; import { UmbChangeEvent } from '@umbraco-cms/backoffice/event'; import { UmbParentEntityContext, type UmbEntityModel, type UmbEntityUnique } from '@umbraco-cms/backoffice/entity'; +import { ensureSlash } from '@umbraco-cms/backoffice/router'; export abstract class UmbTreeItemContextBase< TreeItemType extends UmbTreeItemModel, @@ -449,9 +450,12 @@ export abstract class UmbTreeItemContextBase< return; } - const path = this.#path.getValue(); - const location = window.location.pathname; - const isActive = location.includes(path); + /* Check if the current location includes the path of this tree item. + We ensure that the paths ends with a slash to avoid collisions with paths like /path-1 and /path-1-2 where /path-1 is in both. + Instead we compare /path-1/ with /path-1-2/ which wont collide.*/ + const location = ensureSlash(window.location.pathname); + const comparePath = ensureSlash(this.#path.getValue()); + const isActive = location.includes(comparePath); this.#isActive.setValue(isActive); }