Routing
You can utilize the Angular Router and use the PanelBar as a navigational component.
The Router enables you to load modules which act as root modules for specific paths. The Angular Router loads separate modules for separate components and bootstraps the components. This approach is useful when the paths do not share any main components—for example, public vs. admin sections. To use shared components, move the components into a shared module and import it in the separate module.
To set the functionality, use either of the following approaches:
Using RouterLink Directive
This approach enables you to navigate to the routes upon clicking the PanelBar items and by using the RouterLink
directive. The directive is generated from the routes that are available in the router configuration.
To use the routerLink
directive, you need to import the RouterModule
in your module.
<kendo-panelbar-item ...
[selected]="route.path === selectedId"
[routerLink]="'./' + route.path"
>
</kendo-panelbar-item>
The following example demonstrates how to use routerLink
directive for each item in the PanelBar.
Using Router Service
To get the selected item, you can use the stateChange
event of the PanelBar. The event returns the selected item, which you can then use to navigate to the corresponding route. Use the navigate
method of the Router
service to navigate to a specific route.
public stateChange(data: PanelBarStateChangeEvent): void {
...
this.router.navigate([`./${current.id}`], { relativeTo: this.route });
}
The following example demonstrates how to use the stateChange
event to navigate to a specific route.