Navigate Login or homescreen based on login state

Hi, I have Login Screen and Home screen, I need to navigate Login screen or home screen based on login state, So anyone can provide any sample. I am trying with samples of the ionic guard, In device, it is showing a blank white screen after splash screen, so please help me.

Hello, follow this Ionic 4 Auth Guard to learn more about what you want to do

I did same, But I am getting white blank screen after splash screen

Hi Harikag don’t worry I am here to help you, find below example code for your help do such like this inside your app.component.ts file

initializeApp() {
this.platform.ready().then(() => {
this.statusBar.styleDefault();
this.splashScreen.hide();
this.db.createDatabase()
this.nativeStorage.getItem(“user”).then(res => {
this.router.navigate(["/home"], { skipLocationChange: true });
}).catch(error => {
this.router.navigate(["/login"], { skipLocationChange: true });
});
});
}

cheers!!

Thank you so much for your responce. I will try this solution deffinatily.

I tried your example. But it is giving below error.
ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: ‘chatHome’

Hi
It is great you are near to solution just copy the name of class link from app.routing.module.ts this array
const routes: Routes = [
{
path: ‘’,
redirectTo: ‘login’,
pathMatch: ‘full’
},
{
path: ‘home’,
loadChildren: ‘./home/home.module#HomePageModule’,
//canActivate: [LoggedInGuard]
},
{
path: ‘list’,
loadChildren: ‘./list/list.module#ListPageModule’
},
{ path: ‘login’, loadChildren: ‘./login/login.module#LoginPageModule’ }]

then it will run successfully,

cheers!!