Angular5路由问题
在从一个组件导航到另一个组件的过程中,处理面临路由器问题的angular5 错误显示:无法激活已激活的插座 请查找代码、标题导航和错误的屏幕截图。Angular5路由问题,angular,angularfire2,auth-guard,Angular,Angularfire2,Auth Guard,在从一个组件导航到另一个组件的过程中,处理面临路由器问题的angular5 错误显示:无法激活已激活的插座 请查找代码、标题导航和错误的屏幕截图。 , 提供代码而不是图像。您可以在此处添加一些代码吗。不上传images@Vikas添加了代码,请检查,thanks@AnuradhaGunasekara添加了代码,请检查,谢谢 auth guard.ts @Injectable() export class AuthGuard implements CanActivate { co
,
提供代码而不是图像。您可以在此处添加一些代码吗。不上传images@Vikas添加了代码,请检查,thanks@AnuradhaGunasekara添加了代码,请检查,谢谢
auth guard.ts
@Injectable()
export class AuthGuard implements CanActivate {
constructor(private auth: AngularFireAuth, private router: Router) { }
canActivate(): Observable<boolean> {
return Observable.from(this.auth.authState)
.take(1)
.map(state => !!state)
.do(authenticated => {
if(!authenticated)
this.router.navigate(['/login']);
})
}
}
const routes: Routes = [
{
'path': '',
'component': ThemeComponent,
'canActivate': [AuthGuard],
'children': [
{
'path': 'index',
'loadChildren': '.\/pages\/default\/blank\/blank.module#BlankModule',
},
{
'path': 'profile',
'loadChildren': '.\/pages\/default\/profile\/profile.module#ProfileModule',
},
{
'path': 'stylists',
'loadChildren': '.\/pages\/default\/stylists\/stylists.module#StylistsModule',
},
{
'path': 'customers',
'loadChildren': '.\/pages\/default\/customers\/customers.module#CustomersModule',
},
{
'path': 'services',
'loadChildren': '.\/pages\/default\/services\/services.module#ServicesModule',
},
{
'path': '',
'redirectTo': '/index',
'pathMatch': 'full',
}
],
},
{
'path': '**',
'redirectTo': 'index',
'pathMatch': 'full',
},
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
})
export class ThemeRoutingModule {
}