Hello,
Actually i’m working with Ionic-v4 (Angular), i tried to use all API’s like: .setRoot , .navigateRoot, .pop, .push, using options like replaceUrl:true, skipLocationChange: true, navigateForward, navigateBackward etc… to clear stack pages, but none of these suggestions do the job.
I want to clear all ionic stack pages whenever i logout from the application, this is my logout code i used:
In my service file, here is the logout process:
/**
* Logout connected user
* @param {function} onLoggedOut callback maybe called after logged out
* @param forcedLogout
*/
logout(onLoggedOut = null, forcedLogout = false) {
if (forcedLogout) {
this.frontLogout();
} else {
this.http.post(`${this.config.apiUrl}to-logout`, {})
.subscribe(
data => {
this.frontLogout();
if (onLoggedOut) {
onLoggedOut();
}
}
);
}
}
/**
* Front logout
* @private
*/
private frontLogout() {
localStorage.removeItem('currentUser');
}
in my menu page here is the logout process using the previous service:
/**
* logout service
*/
private disconnect(withNavigation = true) {
this.authService.logout(async () => {
if (withNavigation){
await this.navCtrl.navigateRoot(['/'], ROUTER_CONFIG_BACK);
}
});
}
Important: the ‘/’ route is pointing on a lazyloading module:
app-routing.module.ts
{
path: '',
canActivateChild: [AuthenticatedUserGuard],
loadChildren: () => import('./lancement/lancement.module').then(m => m.LancementPageModule)
},
lancement.module.ts
{
path: '',
component: LancementPage
}
Thank you in advance.
1 post - 1 participant