In index.html I have 2 views:
- sidebar-left: where the menu loads after login.
- content: where the page in question is loaded
I'm using angular-ui-router and after login, the user is redirected to the dashboard.
The dashboard loads the sidebar-left:
.state('dashboard', {
url: "/dashboard",
views: {
'content': {
templateUrl: 'view/dashboard.html',
resolve: {
auth : function ($q, Session) {
var userInfo = Session.getUserInfo();
if (userInfo) return $q.when(userInfo);
else return $q.reject({ authenticated: false });
}
},
controller: 'dashboard'
},
'sidebar-left' : { templateUrl: 'view/sidebar-left.html', controller: 'menu' }
},
})
It turns out that the sidebar-left is common on all pages, by switching from the dashboard to another area the sidebar disappears.
This I solved by adding the "sidebar-left" view on all routes.
It turns out that the "sidebar-left" view is associated with a controller that does a GET to the server and PHP reads the database and returns the menu.
Whenever I change the route, this controller is executed by making an unnecessary GET to the server.
The problem is the logic used, how do I make the menu load only once?