Title Text
const routes: Routes = [
{ path: 'sign-in', component: SignInComponent },
{ path: 'talks', component: TalksComponent, canActivate:[AuthenticationGuard] }
];
@Injectable()
export class AuthenticationGuard {
constructor(private authService:AuthenticationService, private router:Router) { }
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot):
Observable<boolean> | Promise<boolean> | boolean {
if (this.authService.isAuthenticated) {
return true;
}
this.router.navigate(['/']);
return false;
}
}
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpClientModule } from '@angular/common/http';
import { AppComponent } from './app.component';
import { HeroesComponent } from './heroes.component';
import { HeroService } from './hero.service';
@NgModule({
declarations: [AppComponent, HeroesComponent],
imports: [BrowserModule, FormsModule, HttpClientModule],
providers: [HeroService],
bootstrap: [AppComponent]
})
export class AppModule {}
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
template: `
<h1>Heroes</h1>
<app-heroes></app-heroes>
`,
styles: []
})
export class AppComponent {
title = 'app';
}
deck
By simonaco
deck
- 702