Allow component routing for NgbTabset
See original GitHub issueBug description:
I’d like to load different components using the tab set. These components should be accessed by their URL. Currently, I see two ways of achieving this:
- Provide a link with a
routerLink
in thengbTabTitle
template - Use the
tabChange
event and tell the router to navigate.
Option 1 has the drawback that routing only happens if the title is clicked (not the tab)
Option 2 doesn’t allow for copying the link when hovering it
While both options may achieve the desired result, I think there should be a better way (e.g., without adding an empty ngbTabContent
template).
Link to minimally-working plunker that reproduces the issue:
See links provided for Option 1 and 2.
Version of Angular, ng-bootstrap, and Bootstrap:
Angular: 4.x
ng-bootstrap: 1.0.0-alpha.26
Bootstrap: v4.0.0-alpha.6
Issue Analytics
- State:
- Created 6 years ago
- Reactions:28
- Comments:11 (2 by maintainers)
Top Results From Across the Web
component router not working with ng-bootstrap - Stack Overflow
I am writing below code to navigate between tabs and <ngb-tabset> <ngb ...
Read more >Developers - Allow component routing for NgbTabset -
Bug description: I'd like to load different components using the tab set. These components should be accessed by their URL.
Read more >Nav - Angular powered Bootstrap
Router integration is simple: just use standard <router-outlet> component instead of ngbNavOutlet and add [routerLink] directives to nav links. Ex. if you want ......
Read more >Dynamic tabs with Angular 6+ and ng-bootstrap
This is because no routing is taking place when clicking a tab header. 21. Add an onTabChange method to ngb-tabset in the main-content...
Read more >Angular 8/7 Bootstrap | Tabset Tutorial with Options by Example
Let's get started with Bootstrap Tabset component implementation. ... ng new ng-bootstrap-tabset Would you like to add Angular routing?
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I second this issue.
Quick fix :
Incase you are using ng-template for routerlink like below :
<ngb-tabset #tabset="ngbTabset">
<ngb-tab id="tab1">
<ng-template ngbTabTitle>
<a class="btn-link" [routerLink]="['./nestedRoute1']">Tab1</a>
</ng-template>
</ngb-tab>
<ngb-tab id="tab2">
<ng-template ngbTabTitle>
<a class="btn-link" [routerLink]="['./nestedRoute2']">Tab2</a>
</ng-template>
</ngb-tab>
</ngb-tabset>
And facing problem like routing only happens if the title is clicked (not the tab), try removing padding for the outer anchor tag and make the inner anchor tag i.e btn-link in the above code as inline-block and provide padding to it.
Thus any click on the tab will correspond to inner anchor tag with router link.