Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70429

Ionic 4 home page load every time when i close and open app

$
0
0

@ashfan077 wrote:

When the user submits a name it saves in local storage in mobile and it redirects to the second page but the user closes and reopens the application it loads from the first page. below is my code.

This one is my Auth Guard code

 canActivate(
    next: ActivatedRouteSnapshot,
    state: RouterStateSnapshot): boolean {
    if (localStorage.getItem('petData') != null) {
        return true;
    } else {
        this.route.navigateByUrl('/');
        return false;
    }
}

This one is routing

const routes: Routes = [
{
    path: 'home',
    loadChildren: () => import('./home/home.module').then(m => m.HomePageModule)
},
{
    path: '',
    redirectTo: 'home',
    pathMatch: 'full'
},
{
    path: 'dashboard',
    canActivate: [LocalGuardGuard],
    loadChildren: () => import('./dashboard/dashboard.module').then(m => m.DashboardPageModule)
},

This is the first page submit event.

 saveData() {
    // this.storage.set('petData', JSON.stringify(this.petData.petName));
    localStorage.setItem('petData', this.petData.petName);
    Swal.fire({
        // title: this.petData.petName,
        title: 'It is a not pet anymore, It is a ' + this.petData.petName,
        timer: 2000,
        timerProgressBar: true
    });
    this.router.navigateByUrl('/dashboard');
}

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70429

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>