Skip to content

Commit

Permalink
chore(demo): use routerLinkActive instead of custom method (valor-sof…
Browse files Browse the repository at this point in the history
  • Loading branch information
otelnov authored and valorkin committed Jul 18, 2016
1 parent 2b95c95 commit e7dd76b
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 29 deletions.
5 changes: 1 addition & 4 deletions demo/components/main-menu/main-menu.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,11 @@ export class MainMenuComponent {
public hash:string = '';

public constructor(private router:Router) {
this.routes = this.routes.filter((v:any) => v.path !== '**');
this.router.events.subscribe((event:any) => {
if (event instanceof NavigationEnd) {
this.hash = event.url;
}
});
}

public isActive(link:string):boolean {
return this.hash.substring(1) === link;
}
}
23 changes: 3 additions & 20 deletions demo/components/main-menu/main-menu.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,9 @@ <h3 *ngIf="!isBs3"><a href="./#{{hash}}">View in Bootstrap 3</a></h3>
</div>
<div class="section"
*ngFor="let route of routes | SearchFilter:search.text"
[class.active]="isActive(route.path)">
<h3 [routerLink]="[route.path]">{{route.data[0]}}</h3>

<!-- <div class="item">
<h4>
<span [routerLink]="[route.name]">Example</span>
</h4>
</div>
<div class="item">
<h4>
<span [routerLink]="[route.name]">Api</span>
</h4>
</div>
<div class="item">
<h4>
<span [routerLink]="[route.name]">Properties</span>
</h4>
</div>-->
[routerLinkActive]="['active']"
[routerLinkActiveOptions]="{exact: true}">
<a [routerLink]="[route.path]"><h3>{{route.data[0]}}</h3></a>
</div>
</div>
</div>
Expand Down
4 changes: 1 addition & 3 deletions demo/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,7 @@ export const routes:RouterConfig = [
component: TypeaheadSectionComponent
}, {
path: '**',
redirectTo: '',
data: ['Getting started'],
component: GettingStartedSectionComponent
redirectTo: '/'
}
];

Expand Down
3 changes: 1 addition & 2 deletions demo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {Ng2BootstrapConfig, Ng2BootstrapTheme} from '../ng2-bootstrap';
import {MainMenuComponent} from './components/main-menu/main-menu.component';
import {TopMenuComponent} from './components/top-menu/top-menu.component';
import {bootstrap} from '@angular/platform-browser-dynamic';
import {APP_BASE_HREF, HashLocationStrategy, LocationStrategy} from '@angular/common';
import {HashLocationStrategy, LocationStrategy} from '@angular/common';
import {APP_ROUTER_PROVIDERS} from './config';
import {ROUTER_DIRECTIVES, Router, NavigationEnd} from '@angular/router';

Expand Down Expand Up @@ -56,6 +56,5 @@ bootstrap(DemoComponent, [
APP_ROUTER_PROVIDERS,
disableDeprecatedForms(),
provideForms(),
{provide: APP_BASE_HREF, useValue: '/'},
{provide: LocationStrategy, useClass: HashLocationStrategy}
]);

0 comments on commit e7dd76b

Please sign in to comment.