I have created an AuthGuard Service and implemented CanLoad interface to it, as shown below
import { Injectable } from '@angular/core';
import { CanLoad, Router } from '@angular/router';
@Injectable({
providedIn: 'root'
})
export class AuthGuard implements CanLoad {
constructor(private router: Router) { }
canLoad() {
if (localStorage.getItem('isLoggedin')) {
return true;
}
this.router.navigate(['/auth/login']);
return false;
}
}
Below is my App Routing module
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { AuthGuard } from './shared/guard/auth.guard';
const routes: Routes = [
{ path: '', loadChildren: './layout/layout.module#LayoutModule', canLoad: [AuthGuard] },
{ path: 'auth', loadChildren: './auth/auth.module#AuthModule' },
{ path: 'not-found', loadChildren: './not-found/not-found.module#NotFoundModule' },
{ path: '**', redirectTo: 'not-found' }
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
No files are being downloaded when I check the browser networks tab and I see a blank white page and Below is the warning I see in my browser
platform-browser.js:613 Throttling navigation to prevent the browser from hanging. See https://crbug.com/882238. Command line switch --disable-ipc-flooding-protection can be used to bypass the protection