question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow component routing for NgbTabset

See original GitHub issue

Bug 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:

  1. Provide a link with a routerLink in the ngbTabTitle template
  2. 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:closed
  • Created 6 years ago
  • Reactions:28
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

11reactions
chuckconwaycommented, Jul 19, 2017

I second this issue.

5reactions
rtvalluricommented, Jan 9, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found