diff --git a/src/app/app.menu.ts b/src/app/app.menu.ts index 1d75bc06..5de1e553 100644 --- a/src/app/app.menu.ts +++ b/src/app/app.menu.ts @@ -1,7 +1,7 @@ export const menuItems = [ { title: 'Dashboard', - component: 'dashboard', + path: '/pages/dashboard', icon: 'fa fa-home', selected: false, expanded: false, @@ -9,7 +9,7 @@ export const menuItems = [ }, { title: 'Charts', - component: 'charts', + path: '/pages/charts', icon: 'fa fa-bar-chart', selected: false, expanded: false, @@ -17,13 +17,13 @@ export const menuItems = [ subMenu: [ { title: 'Chartist.Js', - component: 'chartist-js', + path: '/chartist-js', }, ] }, { title: 'UI Features', - component: 'ui', + path: '/pages/ui', icon: 'fa fa-laptop', selected: false, expanded: false, @@ -31,25 +31,25 @@ export const menuItems = [ subMenu: [ { title: 'Typography', - component: 'typography', + path: '/typography', }, { title: 'Buttons', - component: 'buttons', + path: '/buttons', }, { title: 'Icons', - component: 'icons', + path: '/icons', }, { title: 'Grid', - component: 'grid', + path: '/grid', }, ] }, { title: 'Form Elements', - component: 'forms', + path: '/pages/forms', icon: 'fa fa-pencil-square-o', selected: false, expanded: false, @@ -57,17 +57,17 @@ export const menuItems = [ subMenu: [ { title: 'Form Inputs', - component: 'inputs', + path: '/inputs', }, { title: 'Form Layouts', - component: 'layouts', + path: '/layouts', }, ] }, { title: 'Tables', - component: 'tables', + path: '/pages/tables', icon: 'fa fa-table', selected: false, expanded: false, @@ -75,13 +75,13 @@ export const menuItems = [ subMenu: [ { title: 'Basic Tables', - component: 'basictables', + path: '/basictables', } ] }, { title: 'Maps', - component: 'maps', + path: '/pages/maps', icon: 'fa fa-map-marker', selected: false, expanded: false, @@ -89,19 +89,19 @@ export const menuItems = [ subMenu: [ { title: 'Google Maps', - component: 'googlemaps', + path: '/googlemaps', }, { title: 'Leaflet Maps', - component: 'leafletmaps', + path: '/leafletmaps', }, { title: 'Bubble Maps', - component: 'bubblemaps', + path: '/bubblemaps', }, { title: 'Line Maps', - component: 'linemaps', + path: '/linemaps', } ] }, @@ -114,11 +114,11 @@ export const menuItems = [ subMenu: [ { title: 'Login', - url: '#/login', + path: '/login', }, { title: 'Register', - url: '#/register', + path: '/register', } ] }, diff --git a/src/app/theme/components/baSidebar/baSidebar.component.ts b/src/app/theme/components/baSidebar/baSidebar.component.ts index 89eef900..7241714b 100644 --- a/src/app/theme/components/baSidebar/baSidebar.component.ts +++ b/src/app/theme/components/baSidebar/baSidebar.component.ts @@ -1,10 +1,9 @@ -import {Component, ElementRef, HostListener, ViewEncapsulation} from '@angular/core'; -import {Router} from '@angular/router'; - -import {AppState} from '../../../app.state'; -import {layoutSizes} from '../../../theme'; -import {BaSlimScroll} from '../../../theme/directives'; -import {BaSidebarService} from './baSidebar.service'; +import {Component, ElementRef, HostListener, ViewEncapsulation} from "@angular/core"; +import {Router} from "@angular/router"; +import {AppState} from "../../../app.state"; +import {layoutSizes} from "../../../theme"; +import {BaSlimScroll} from "../../../theme/directives"; +import {BaSidebarService} from "./baSidebar.service"; @Component({ selector: 'ba-sidebar', @@ -35,7 +34,9 @@ export class BaSidebar { private _state:AppState) { this.menuItems = this._sidebarService.getMenuItems(); - // this._onRouteChange = this._router.root.subscribe((path) => this._selectMenuItem()); + this._onRouteChange = this._router.events.subscribe(() => { + this._selectMenuItem(); + }); this._state.subscribe('menu.isCollapsed', (isCollapsed) => { this.isMenuCollapsed = isCollapsed; }); @@ -49,7 +50,7 @@ export class BaSidebar { } public ngOnDestroy():void { - // this._onRouteChange.unsubscribe(); + this._onRouteChange.unsubscribe(); } public ngAfterViewInit():void { diff --git a/src/app/theme/components/baSidebar/baSidebar.html b/src/app/theme/components/baSidebar/baSidebar.html index cdb4d344..c8956c7e 100644 --- a/src/app/theme/components/baSidebar/baSidebar.html +++ b/src/app/theme/components/baSidebar/baSidebar.html @@ -4,10 +4,10 @@ [ngClass]="{'selected': item.selected && !item.expanded, 'with-sub-menu': item.subMenu, 'ba-sidebar-item-expanded': item.expanded}"> - + {{ item.title }} - + {{ item.title }} @@ -31,17 +31,17 @@ [ngClass]="{expanded: subitem.expanded, 'slide-right': subitem.slideRight}">
  • - + {{ subSubitem.title }} - + {{ subSubitem.title }}
  • - {{ subitem.title}} - {{ subitem.title}} diff --git a/src/app/theme/components/baSidebar/baSidebar.service.ts b/src/app/theme/components/baSidebar/baSidebar.service.ts index 7653aae1..ce9a5f41 100644 --- a/src/app/theme/components/baSidebar/baSidebar.service.ts +++ b/src/app/theme/components/baSidebar/baSidebar.service.ts @@ -1,16 +1,17 @@ import {Injectable} from '@angular/core'; import {menuItems} from '../../../app.menu'; +import {Router, UrlTree} from "@angular/router"; @Injectable() export class BaSidebarService { - private _router; + private _router:Router; public getMenuItems():Array { return menuItems; } - public setRouter(router): BaSidebarService { + public setRouter(router:Router):BaSidebarService { this._router = router; return this; } @@ -20,14 +21,14 @@ export class BaSidebarService { let assignCurrent = (menu) => (menu.selected ? currentMenu = menu : null); - items.forEach((menu: any) => { + items.forEach((menu:any) => { - this._selectItem([menu.component], menu); + this._selectItem([menu.path], menu); assignCurrent(menu); if (menu.subMenu) { menu.subMenu.forEach((subMenu) => { - this._selectItem([menu.component, subMenu.component], subMenu, menu); + this._selectItem([menu.path, subMenu.path], subMenu, menu); assignCurrent(subMenu); }); } @@ -43,11 +44,22 @@ export class BaSidebarService { } } - private _isCurrent(route) { - return route ? this._router.isRouteActive(route) : false; + private _isCurrent(route:UrlTree):boolean { + if (!route) + return false; + + return this._router.url === this._router.serializeUrl(route); } - private _generateRoute(instructions) { - return instructions.filter(i => typeof i !== 'undefined').length > 0 ? this._router.generate(instructions) : null; + private _generateRoute(instructions:any[]):UrlTree { + if (!instructions) + return null; + + instructions = instructions.filter(item => !!item); + + if (instructions.length === 0) + return null; + + return this._router.createUrlTree(instructions); } }