@shorstmann wrote:
Hi all,
i have a app with a login-page.
If the user starts the app for the first time the login-page will be shown and the user has to login. If that was succesfull the app redirects the user to the menu-page (and this loads the tabs and so on).
Now, if the user closes the app or sends it to the background and reopens the app, the login-page is shown for a short period of time (less than 1 second) and it redirects again to the menu-page.
How can i prevent the login-page to be shown when the user is already logged in and the user is reopening the app? With ionic 3 that was no problem for me (using setRoot) but now with ionic 4 i face this problem (maybe because of the routes…?)
Here are some code snippets from my code:
app-routing.module.ts
const routes: Routes = [ { path: '', redirectTo: 'login', pathMatch: 'full' }, { path: 'login', loadChildren: './pages/login/loginPage.module#LoginPageModule' }, { path: 'menu', canActivate: [AuthGuard], loadChildren: './pages/menu/menu.module#MenuPageModule' }, ]
app.component.ts
this.splashScreen.hide(); this.authenticationService.authenticationState.subscribe(state => { if (state) { this.navController.navigateRoot(['menu/tabs/dashboard']); } else { this.navController.navigateRoot('login') } });
In my AuthGuard i simply check if the user is logged in and return true or false. I followed this tutorial: https://devdactic.com/ionic-4-login-angular/
What do i have to do?
Posts: 3
Participants: 2