0

在从一个组件导航到另一个组件时处理 angular5 面临的路由器问题错误显示:无法激活已激活的插座请查找代码、标题导航和错误的屏幕截图。
错误截图

在此处输入图像描述
路由模块认证保护在此处输入图像描述
在此处输入图像描述

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']);
            })
    }
}

主题路由.module.ts

    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 {
 }

我的应用程序文件结构的屏幕截图

4

0 回答 0