File app.routes
Protected routes have canActivate
binded to Guard
import { provideRouter, Router, RouterConfig, CanActivate } from '@angular/router';
//components
import { LoginComponent } from './login/login.component';
import { DashboardComponent } from './dashboard/dashboard.component';
export const routes: RouterConfig = [
{ path: 'login', component: LoginComponent },
{ path: 'dashboard', component: DashboardComponent, canActivate: [AuthGuard] }
}
Export the APP_ROUTER_PROVIDERS to be used in app bootstrap
export const APP_ROUTER_PROVIDERS = [
AuthGuard,
provideRouter(routes)
];