Clear Routing Stack does not work

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){
                // the '/' is pointing on lazymodule routing: lancement.module.ts
                await this.navCtrl.navigateRoot(['/'], ROUTER_CONFIG_BACK);
            }
        });
    }

Important: the ‘/’ route is pointing on a lazyloading module:
app-routing.module.ts

   {
        path: '',  // after logout redirection route
        canActivateChild: [AuthenticatedUserGuard],
        loadChildren: () => import('./lancement/lancement.module').then(m => m.LancementPageModule)
    },

lancement.module.ts

 {
    path: '',  // after logout redirection route
    component: LancementPage
  }

it’s maybe useful to mention, that even when testing on browser, the browser history does not clear too with the used api’s like .navigateRoot().

Thank you in advance.

So the router in v4 doesn’t actually behave the same way as it did in v3, sop this is to be expected.

Basically, in V4/V5, the router actually uses the built-in browser history, so functions like setRoot don’t actually clear the history stack. Since the browser does not provided a way to clear out browser history, there’s nothing really to do here at the moment.

Hello ,

thank you for your answer …

but is there any other alternative to deal with this issue ?