diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index 1e0d9ec..2bf82c7 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -1,11 +1,29 @@ import { NgModule } from '@angular/core'; import { RouterModule, Routes } from '@angular/router'; +import { AuthGuard } from './auth/auth.guard'; import { HomeComponent } from './home/home.component'; import { NonAuthenticatedComponent } from './non-authenticated/non-authenticated.component'; +import { ListComponent } from './users/list/list.component'; +import { UsersComponent } from './users/users.component'; +import { WelcomeComponent } from './users/welcome/welcome.component'; const routes: Routes = [ { path: '', pathMatch: 'full', redirectTo: 'home' }, { path: 'home', component: HomeComponent }, + { + path: 'users', + component: UsersComponent, + children: [ + { path: '', pathMatch: 'full', redirectTo: 'welcome' }, + { path: 'non-auth', component: NonAuthenticatedComponent }, + { path: 'welcome', component: WelcomeComponent }, + { + path: '', + canActivateChild: [AuthGuard], + children: [{ path: 'list', component: ListComponent }], + }, + ], + }, { path: 'non-auth', component: NonAuthenticatedComponent }, ]; diff --git a/src/app/app.component.html b/src/app/app.component.html index 181bc03..c3bdf10 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -2,6 +2,7 @@ {{ title }} + + + + `, + changeDetection: ChangeDetectionStrategy.OnPush, +}) +export class UsersComponent {} diff --git a/src/app/users/users.module.ts b/src/app/users/users.module.ts new file mode 100644 index 0000000..a598eb3 --- /dev/null +++ b/src/app/users/users.module.ts @@ -0,0 +1,15 @@ +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { RouterModule } from '@angular/router'; + +import { WelcomeComponent } from './welcome/welcome.component'; +import { UsersComponent } from './users.component'; +import { AngularMaterialModule } from '../angular-material/angular-material.module'; +import { ListComponent } from './list/list.component'; + +@NgModule({ + declarations: [WelcomeComponent, UsersComponent, ListComponent], + exports: [WelcomeComponent, UsersComponent, ListComponent], + imports: [AngularMaterialModule, CommonModule, RouterModule], +}) +export class UsersModule {} diff --git a/src/app/users/welcome/welcome.component.spec.ts b/src/app/users/welcome/welcome.component.spec.ts new file mode 100644 index 0000000..949ca3c --- /dev/null +++ b/src/app/users/welcome/welcome.component.spec.ts @@ -0,0 +1,25 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { WelcomeComponent } from './welcome.component'; + +describe('WelcomeComponent', () => { + let component: WelcomeComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ WelcomeComponent ] + }) + .compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(WelcomeComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/users/welcome/welcome.component.ts b/src/app/users/welcome/welcome.component.ts new file mode 100644 index 0000000..b51055f --- /dev/null +++ b/src/app/users/welcome/welcome.component.ts @@ -0,0 +1,8 @@ +import { Component, ChangeDetectionStrategy } from '@angular/core'; + +@Component({ + selector: 'app-welcome', + template: `

Welcome

`, + changeDetection: ChangeDetectionStrategy.OnPush, +}) +export class WelcomeComponent {} diff --git a/src/index.html b/src/index.html index 48fc669..0a2c9c1 100644 --- a/src/index.html +++ b/src/index.html @@ -1,16 +1,22 @@ - + - - - AngularGuards - - - - - - - - - - + + + Angular Guards - CanActivateChild + + + + + + + + + +