This example starts using tabs. I need to start from a page without tabs and be able to move to a page with tabs. From there this indeed works. Is it possible to adapt this example to what I want?
I’m starting to think this is just not possible with UI Router. I’ve never seen anyone successfully implement this at least. If I’m wrong, please weigh in.
So to reiterate what I’m trying to achieve:
First screen is page without tabs. Contains a link to the second screen.
Second screen is page with tabs. Every tab contains links to detailed views.
Third screen is a detailed view.
How can I set up routing so that when I navigate from screen 1, to the screen with the tabs, to the detailed view, and I go back again to the screen with tabs, the tabs know which tab was open?
@coen_warmer this is a good question - for now I would suggest manually saving the tab’s state when leaving. Use tab’s on-deselect or scope.$on(’$destroy’) in a tab controller and save the current state name/params in a service, then re-set via $state.go the remembered state if the tab is reselected.
This however is something I’ve noticed to and would be good to have in core - tabs remembering their state somehow - but I’m not sure of a good way to do it yet.
@coen_warmer I’m having the exact same issue at the moment; I need to save my $stateParams between a tab switch (the data set is fetched using these params, and the tabs just represent a different view; map or list)
Regarding your question about which service to use; I recommend localStorageService
Works perfectly for all my other storage needs so far. But keep in mind that a browser’s localStorage is limited to max 5MB. I’m now playing with the idea to clear this localStorage onExit (an event that is triggered by UI-Router and can be handled when defining the state) when the user leaves the tab view (my app contains more views than just the tab view).
I don’t know what you might think of as 'state of the tabbut in my case I'm just saving$stateParams` to a localStorage and re-apply these params when the parent state has changed.
So with that solution, we have to use ng-switch inside tabs.html to avoid changing views stack when navigating from tabs. But apparently, that will make the code so strange and ugly, and cause more problems since it will ruin your original design of the relation for those states.
So the Solution I choose:
Quite simple, just duplicate states inside your config.router.js, for example:
if you have state app.chatting that need to access from tabs
then duplicate a new one: app.tabs.chatting , so both them will have nav buttons in the right time
they could share exact same code, also our states relation could survive.
Hope this will help you, I think there should be a better solution in the future.