I found a solution, rather simple.
Instead of adding or removing items from the menu (routes, that is I think impossible), it's simpler to play on their visibility, you can add properties to the items of the menu (visible, index, ..., whatever you want), for instance you can do this (it is in config.route.js):
var persistantRoutes = [
{
url: '/await',
config: {
title: '',
templateUrl: 'app/await/await.html',
settings: {
nav: 1,
content: "",
index: 0,
visible: false
}
}
}, {
url: '/reinit',
config: {
title: '',
templateUrl: 'app/reinit/reinit.html',
settings: {
nav: 2,
content: "",
index: 0,
visible: false
}
}
}, {
...
routes = persistantRoutes;
In the viewmodel of the menu (in my case : sidebar.js), you can do this :
function activate() {
authenticationService.checkAuthentication().then(getNavRoutes);
}
function getNavRoutes() {
vm.navRoutes = routes.filter(function (r) {
if (authenticationService.currentUser.isAuthenticated) {
switch (r.config.title) {
case "login":
case "register":
r.config.settings.visible = false;
break;
case "userHomePage":
r.url = "/";
r.config.settings.visible = true;
r.config.settings.nav = 3;
break;
case "FGHomePage":
r.url = "/FGHomePage";
r.config.settings.nav = 4;
break;
}
}
else {
switch (r.config.title) {
case "login":
case "register":
r.config.settings.visible = true;
break;
case "userHomePage":
r.url = "/userHomePage";
r.config.settings.visible = false;
r.config.settings.nav = 4;
break;
case "FGHomePage":
r.url = "/";
r.config.settings.nav = 3;
break;
}
}
if (r.config.settings.visible == true) {
return r.config.settings && r.config.settings.nav;
}
}).sort(function (r1, r2) {
return r1.config.settings.nav - r2.config.settings.nav;
});
}
I have done a service : authenticationService, that allows you to know if the current user is authenticated, knowing this you can render or not the items of the menu.
That is I think rather simple.
Regards.