相关疑难解决方法(0)

Auth Guard canActivate 由于某种原因不起作用

当我canActivate在路由上添加 AuthGuard 服务时,当我尝试去时应用程序崩溃 /profile并将我重定向到localhost:4200,甚至没有/home并给出以下错误:

错误错误:“[对象对象]”

在此处输入图片说明

我的代码:

app.routing.ts

import { NgModule } from '@angular/core';
import { Routes, RouterModule, CanActivate } from '@angular/router';
import { HomeComponent } from './home/home.component';
import { ProfileComponent } from './profile/profile.component';
import { LoginComponent } from './login/login.component';

import { AuthGuardService as AuthGuard } from './auth-guard.service';

const routes: Routes = [
  {path:'', redirectTo:'/home', pathMatch:'full'},
	{path:'home',component: HomeComponent},
  {path:'login',component: LoginComponent},
  {path:'profile',component: ProfileComponent,canActivate: [AuthGuard]}
];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  providers: [AuthGuard],
  exports: [RouterModule]
})
export class …
Run Code Online (Sandbox Code Playgroud)

guard canactivate angular

6
推荐指数
1
解决办法
8087
查看次数

标签 统计

angular ×1

canactivate ×1

guard ×1