あなたはルートガードあなたのルーティングに
import { AngularFireAuth } from 'angularfire2/auth';
import { Injectable } from '@angular/core';
import { Router, ActivatedRouteSnapshot, RouterStateSnapshot, CanActivate } from '@angular/router';
@Injectable()
export class AuthGuard implements CanActivate {
loggedIn = false;
constructor(private dummyService: DummyService, private router: Router) {
}
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
//To get the data in the url for instance,'product/1'
const productId = route.params.id;
//here get the data and do the necessary logic
return this.dummyService.SomeFunction
.map(authState => !!authState) need to return a boolean
.do(auth => {
//user is not the owner of the data so redirect them somewhere else
if (!auth) {
this.router.navigate(['/login']);
}
//if you got here, then the user is the owner of the data.
}).take(1);
}
}
、この
{
path: 'product/:id',
component: SomeComponent,
canActivate: [AuthGuard ]
}
を追加し、app.moduleであなたのプロバイダでAuthGuard
を追加する必要があります。
さらに詳しい情報:
CanActivate - 角度のhttps://angular.io/api/router/CanActivate
バージョンを使用していますか? –
角4.残念ですが、私はOPを更新しました – derrickrozay