I would like to use AngularJS UI Bootstrap Tabs in my project, but I need it to support routing.
For example:
Tab URL
--------------------
Jobs /jobs
Invoices /invoices
Payments /payments
As far as I can tell from the source code, the current tabs
and pane
directives doesn't support routing.
What would be the best way to add routing?
Agree with the use of UI-Router which tracks states and works great with nested views. Speaking particularly of your Bootstrap tabs issue there is a great implementation that leverages UI Router: UI-Router Tabs
I got tabs with routing working the following way.
It's able to do everything you want from dynamic tabs, and it's actually very simple.
ui-view
, so it can dynamically load templates,active
.Define the tabs with a parameter in your router
The tabs template (tabs.html) is
Which is paired with a very simple controller for getting the current active tab:
This aught to be able to do what you want:
https://github.com/angular-ui/ui-router
you could pass your own custom key value pairs in the route definition and achieve this. here's a good example: http://www.bennadel.com/blog/2420-Mapping-AngularJS-Routes-Onto-URL-Parameters-And-Client-Side-Events.htm
This answer really helped me http://odetocode.com/blogs/scott/archive/2014/04/14/deep-linking-a-tabbed-ui-with-angularjs.aspx (very simple but powerful solution)
just a small add to accepted answer: i needed to keep the current tab at page refresh so i used a switch like this: