Ionic 4 Skip Start-Page when user is logged in

I have to repeat… if you do it like i did (find the code above!) it will work as intended!

Can You please help me to solve this issue…

can i just look the sample code that u are currently using?

Where is the GlobalProvider Implementation?

Dear Sir,

Please suggest me, how to skip home page when I reopen the app. It is showing 2 to 3 sec before tab page open.

Please check the below attachment.

Regards,

Rupali

(Attachment app.txt is missing)

I have written my code which I used. Here my problem is, I want to skip home page when I reopen the app, but home page is showing 2-3 sec before open the tab page. Please help me to solve this issue.

** in app.component.ts**
import { Storage } from ‘@ionic/storage’;
import { Router } from ‘@angular/router’;
import { AuthServiceService } from ‘./services/auth-service.service’;
import { BehaviorSubject, Observable } from ‘rxjs’;
@Component({
selector: ‘app-root’,
templateUrl: ‘app.component.html’,
styleUrls: [‘app.component.scss’]
})
export class AppComponent {
authState = new BehaviorSubject(false);
constructor( private router : Router, public storage : Storage, private authService : AuthServiceService) {
this.initializeApp();
}
initializeApp() {
this.platform.ready().then(() => {
this.authService.authState.subscribe(state=>{
if(state){
this.router.navigateByUrl(’/tabs/tab1’),
this.splashScreen.hide();
}
else{
this.router.navigate([’/home’]);
this.splashScreen.hide();
}
})
})
}
}
in auth-service.service.ts
import { Injectable } from ‘@angular/core’;
import { Platform } from ‘@ionic/angular’;
import { Storage } from ‘@ionic/storage’;
import { BehaviorSubject, Observable, observable } from ‘rxjs’;
import { Router } from ‘@angular/router’;
@Injectable({
providedIn: ‘root’
})

export class AuthServiceService {
   authState = new BehaviorSubject(false);
constructor( public storage : Storage,private platform : Platform,     private router : Router) {
            this.platform.ready().then(response=>{
      this.checkStatus();
   
         })
}
checkStatus(){
this.storage.get('TOKEN_KEY').then(val=>{
  if(val){
    this.authState.next(true);
  }
})  
}

agreement(){
return this.storage.set(‘TOKEN_KEY’,‘message’).then(res=>{
this.router.navigateByUrl(’/tabs/tab1’);
this.authState.next(true);
})
}
isAuthenticated(){
return this.authState.value;
}
}
in authguard.guard.ts
import { Injectable } from ‘@angular/core’;
import { CanActivate,CanDeactivate } from ‘@angular/router’;
import { AuthServiceService } from ‘…/services/auth-service.service’;
@Injectable({
providedIn: ‘root’
})
export class AuthguardGuard implements CanActivate {
constructor(public authService : AuthServiceService){ }
canActivate(): boolean {
return this.authService.isAuthenticated();
}
}
in home-page.page.ts
import { Component } from ‘@angular/core’;
import { Router } from ‘@angular/router’;
import { Storage } from ‘@ionic/storage’;
import { AuthServiceService } from ‘…/services/auth-service.service’;
@Component({
selector: ‘app-home-page’,
templateUrl: ‘./home-page.page.html’,
styleUrls: [’./home-page.page.scss’],
})
export class HomePagePage {
constructor( public router : Router,
public storage : Storage,
public authService : AuthServiceService) { }
agree(){
this.authService.agreement();
}
}
in app-routing.module.ts
import { NgModule } from ‘@angular/core’;
import { PreloadAllModules, RouterModule, Routes } from ‘@angular/router’;
import { AuthguardGuard } from ‘./guard/authguard.guard’;

const routes: Routes = [

{ path: ‘’, redirectTo: ‘home’, pathMatch: ‘full’ },
{ path: ‘home’,
loadChildren: () => import(’./home-page/home-page.module’).then( m => m.HomePagePageModule)
},
{ path: ‘tabs’,
loadChildren: () => import(’./tabs/tabs.module’).then(m => m.TabsPageModule),canActivate: [AuthguardGuard]
}
];
@NgModule({
imports: [RouterModule.forRoot(routes,{preloadingStrategy:PreloadAllModules}) ],
exports: [RouterModule]
})
export class AppRoutingModule {}

Regards,

Rupali

It is just a custom class where i do some stuff like setting and getting user data.