I am currently developing a tab-based page that displays data using UI-Router in AngularJs to manage states.
My main goal is to have one default tab open when the page loads. Each tab contains sub tabs, and I want a default sub tab to be open whenever a tab is changed.
During testing, I experimented with the use of the onEnter
function where I tried to navigate to the desired substate using $state.go('mainstate.substate');
. However, I encountered issues related to loop effects as each call to a substate triggered its parent state, creating an infinite loop.
$stateProvider
.state('main', {
url: '/main',
templateUrl: 'main.html',
onEnter: function($state) {
$state.go('main.street');
}
})
.state('main.street', {
url: '/street',
templateUrl: 'submenu.html',
params: {tabName: 'street'}
})
You can view a demo of my progress on Plunker.
Although everything seems to be functioning correctly at the moment, I am still facing the issue of not having the default tab open as intended.
I welcome any suggestions, feedback, or ideas you may have to help me resolve this challenge. Thank you.