firebaseに接続された簡単なアプリケーションがあります。ログイン時に、ユーザーを自分のプロフィールページにリダイレクトするだけです。しかし、何らかの奇妙な理由から、リダイレクトは起こっていません。角度2.0 Router.navigateはログイン後にリダイレクトされません
私は同じような問題のように聞こえるhereの外観を持っていますが、残念なことにそこには解決策はありません。
リダイレクトを別のページ(認証ガードを持たないページ)に変更すると動作するようですので、問題はそこにあると思いますが、修正方法はわかりません。
onLogin() {
this.authService.signinUser(this.loginForm.value);
}
そして、私のauth.service.ts
:それはユーザーがサインインが私のサービスを呼び出したら、ここで
は、私のコードです。ここ
public signinUser(user: User) {
firebase.auth().signInWithEmailAndPassword(user.email, user.password)
.catch(function (error) {
// Handle Errors here.
let errorCode = error.code;
let errorMessage = error.message;
// todo
console.log(errorCode);
console.log(errorMessage);
});
this.router.navigate(['/profile']); //not working
//this.router.navigate(['/']); //working
}
は私のapp.routing.ts
const APP_ROUTES: Routes = [
{ path: '', component: HomeComponent },
{ path: 'login', component: LoginComponent },
{ path: 'signup', component: SignupComponent },
{ path: 'profile', component: ProfileComponent, canActivate: [AuthGuard] },
];
export const routing = RouterModule.forRoot(APP_ROUTES);
そして、ここにあります私です。auth.guard.ts
@Injectable()
export class AuthGuard implements CanActivate {
constructor(private authService: AuthService) {}
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
return this.authService.isAuthenticated().first();
}
}
フルプロジェクトはgithubです。別の設定を確認する必要がある場合は、プロジェクト全体がgithubにあります。
コンソールに何かエラーがありますか? – Sefa
@SefaÜmitOray絶対に何も、コンソールはすべてきれいです。ちょっと奇妙なのは、「サインイン」ボタンを再度クリックすると、リダイレクトされますが、2回目の試行だけです。 – gudthing
@SefaÜmitOrayログインしているときに何が返されますか? 'canActivate(ルート:ActivatedRouteSnapshot、状態:RouterStateSnapshot):観測可能 | boolean { this.authService.isAuthenticated()。first();を返します。 } ' –