diff --git a/src/app/theme/components/baSidebar/baSidebar.component.ts b/src/app/theme/components/baSidebar/baSidebar.component.ts index 7cf37c05..929b4662 100644 --- a/src/app/theme/components/baSidebar/baSidebar.component.ts +++ b/src/app/theme/components/baSidebar/baSidebar.component.ts @@ -35,7 +35,7 @@ export class BaSidebar { private _state:AppState) { this.menuItems = this._sidebarService.getMenuItems(); - this._onRouteChange = this._router.root.subscribe((path) => this._selectMenuItem(path)); + this._onRouteChange = this._router.root.subscribe((path) => this._selectMenuItem()); this._state.subscribe('menu.isCollapsed', (isCollapsed) => { this.isMenuCollapsed = isCollapsed; }); @@ -113,9 +113,9 @@ export class BaSidebar { return window.innerWidth <= layoutSizes.resWidthCollapseSidebar; } - private _selectMenuItem(currentPath = null):void { + private _selectMenuItem():void { - let currentMenu = this._sidebarService.setRouter(this._router).selectMenuItem(this.menuItems, currentPath); + let currentMenu = this._sidebarService.setRouter(this._router).selectMenuItem(this.menuItems); this._state.notifyDataChanged('menu.activeLink', currentMenu); // hide menu after natigation on mobile devises if (this._shouldMenuCollapse()) { diff --git a/src/app/theme/components/baSidebar/baSidebar.service.ts b/src/app/theme/components/baSidebar/baSidebar.service.ts index 198811d8..7653aae1 100644 --- a/src/app/theme/components/baSidebar/baSidebar.service.ts +++ b/src/app/theme/components/baSidebar/baSidebar.service.ts @@ -15,19 +15,19 @@ export class BaSidebarService { return this; } - public selectMenuItem(items:Array, currentPath:string) { + public selectMenuItem(items:Array) { let currentMenu; let assignCurrent = (menu) => (menu.selected ? currentMenu = menu : null); items.forEach((menu: any) => { - this._selectItem(currentPath, [menu.component], menu); + this._selectItem([menu.component], menu); assignCurrent(menu); if (menu.subMenu) { menu.subMenu.forEach((subMenu) => { - this._selectItem(currentPath, [menu.component, subMenu.component], subMenu, menu); + this._selectItem([menu.component, subMenu.component], subMenu, menu); assignCurrent(subMenu); }); } @@ -35,9 +35,9 @@ export class BaSidebarService { return currentMenu; } - private _selectItem(currentPath, instructions, item, parentMenu = null) { + private _selectItem(instructions, item, parentMenu = null) { let route = this._generateRoute(instructions); - item.selected = !item.disabled && this._isCurrent(route) && this._resolvePath(route, '') == currentPath; + item.selected = !item.disabled && this._isCurrent(route); if (parentMenu) { parentMenu.expanded = parentMenu.expanded || item.selected; } @@ -50,13 +50,4 @@ export class BaSidebarService { private _generateRoute(instructions) { return instructions.filter(i => typeof i !== 'undefined').length > 0 ? this._router.generate(instructions) : null; } - - private _resolvePath(instruction, collected) { - if (instruction !== null) { - collected += instruction.urlPath + '/'; - return this._resolvePath(instruction.child, collected) - } else { - return collected.slice(0, -1); - } - } }