|
const routes = [
{
path: 'products', component: ProductsComponent, text: 'Products',
children: [
{ path: 'javascript', component: JavaScriptComponent, text: 'JavaScript' },
{ path: 'angular', component: AngularComponent, text: 'Angular' }
]
},
{ path: 'services', component: ServicesComponent, text: 'Services' },
{ path: 'about', component: AboutComponent, text: 'About Us' },
{ text: 'Careers', component: ProductsComponent, path:'' },
{ text: 'Sign In', component: ProductsComponent, path:'' }
];
@NgModule({
declarations: [ AppComponent,ServicesComponent, ProductsComponent, JavaScriptComponent, AboutComponent, AngularComponent ], imports: [ SidebarModule, BrowserModule, RadioButtonModule, MenuAllModule, DropDownListModule, ButtonModule, TreeViewAllModule, ListViewAllModule,RouterModule.forRoot(routes, {onSameUrlNavigation: 'reload'})],providers: [{ provide: APP_BASE_HREF, useValue: window.location.pathname }], bootstrap: [AppComponent]
}) |
|
export class AppComponent {
@ViewChild('sidebarMenuInstance')
public sidebarMenuInstance: SidebarComponent;
public width: string = '220px';
public mediaQuery: string = ('(min-width: 600px)');
public target: string = '.main-content';
public dockSize: string = '50px';
public enableDock: boolean = true;
public menuItems: any[];
public navigationId: number;
constructor(private router: Router) {
this.menuItems = this.mapItems(router.config);
}
// convert the routes to menu items.
private mapItems(routes: any[], path?: string): any[] {
return routes.map(menuItems => {
const result: any = {
text: menuItems.text,
path: (path ? `${ path }/` : '') + menuItems.path
};
if (menuItems.children) {
result.items = this.mapItems(menuItems.children, menuItems.path);
}
return result;
});
}
ngOnInit(){
this.router.navigate([ 'products' ]);
}
} |