当我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)