refactor(app): permit to use PathLocationStrategy

close #258
This commit is contained in:
tibing 2016-10-19 17:21:25 +03:00
parent 0beef0b8a9
commit ec0e5aa673
5 changed files with 20 additions and 21 deletions

View file

@ -245,20 +245,18 @@ export const PAGES_MENU = [
},
children: [
{
path: '',
path: ['/login'],
data: {
menu: {
title: 'Login',
url: '#/login'
title: 'Login'
}
}
},
{
path: '',
path: ['/register'],
data: {
menu: {
title: 'Register',
url: '#/register'
title: 'Register'
}
}
}

View file

@ -76,8 +76,12 @@ export class BaMenuService {
}
// we have to collect all paths to correctly build the url then
item.route.paths = parent && parent.route && parent.route.paths ? parent.route.paths.slice(0) : [];
item.route.paths.push(item.route.path);
if (Array.isArray(item.route.path)) {
item.route.paths = item.route.path;
} else {
item.route.paths = parent && parent.route && parent.route.paths ? parent.route.paths.slice(0) : ['/'];
item.route.paths.push(item.route.path);
}
if (object.children && object.children.length > 0) {
item.children = this._convertArrayToItems(object.children, item);
@ -95,10 +99,6 @@ export class BaMenuService {
protected _prepareItem(object:any):any {
if (!object.skip) {
let itemUrl = this._router.serializeUrl(this._router.createUrlTree(object.route.paths));
object.url = object.url ? object.url : '#' + itemUrl;
object.target = object.target || '';
object.pathMatch = object.pathMatch || 'full';
return this._selectItem(object);
@ -108,11 +108,7 @@ export class BaMenuService {
}
protected _selectItem(object:any):any {
if (object.children || object.pathMatch === 'full') {
object.selected = object.url === ('#' + this._router.url);
} else {
object.selected = ('#' + this._router.url).indexOf(object.url) === 0;
}
object.selected = this._router.isActive(this._router.createUrlTree(object.route.paths), object.pathMatch !== 'full');
return object;
}
}

View file

@ -1,7 +1,10 @@
<li *ngIf="!menuItem.hidden" [title]="menuItem.title" [ngClass]="{'al-sidebar-list-item': !child, 'ba-sidebar-sublist-item': child, 'selected': menuItem.selected && !menuItem.expanded, 'with-sub-menu': menuItem.children, 'ba-sidebar-item-expanded': menuItem.expanded}">
<a *ngIf="!menuItem.children && !menuItem.url" (mouseenter)="onHoverItem($event, item)" [routerLink]="menuItem.route.paths" class="al-sidebar-list-link">
<i *ngIf="menuItem.icon" class="{{ menuItem.icon }}"></i><span>{{ menuItem.title }}</span>
</a>
<a *ngIf="!menuItem.children" (mouseenter)="onHoverItem($event, item)" [href]="menuItem.url" [target]="menuItem.target" class="al-sidebar-list-link">
<a *ngIf="!menuItem.children && menuItem.url" (mouseenter)="onHoverItem($event, item)" [href]="menuItem.url" [target]="menuItem.target" class="al-sidebar-list-link">
<i *ngIf="menuItem.icon" class="{{ menuItem.icon }}"></i><span>{{ menuItem.title }}</span>
</a>