Angular2路由问题-区域感知错误顺序中没有元素 [英] Angular2 routing issues - Zone aware error No elements in sequence
问题描述
我已经搜索了很多,却找不到解决我问题的答案.所以我要发布这个问题.
I have searched quite a bit and couldn't find any answer that solved my problem. So I am posting this question.
我的问题与此问题非常相似. Angular 2.0.1路由器EmptyError:顺序无元素
My issue is very similar to this question. Angular 2.0.1 Router EmptyError: no elements in sequence
但是我什至无法通过添加pathMatch:'full',来解决它.
But I couldn't resolve it even by adding pathMatch: 'full',.
当尝试从列表中导航时(导航到详细信息视图),我收到间歇性的zonewaware错误. 下面是我的模块.
I am getting an intermittent zonewaware error when try to navigate from a list table (navigates to detail view) below is my module.
@NgModule({
imports: [
CommonModule,
RouterModule.forChild([
{
path: 'teams',
component: TeamsListComponent,
pathMatch: 'full',
resolve: {
TeamTemplate: TeamListTemplatesResolver
},
canActivate: [AuthenticatedGuard]
}, {
path: 'teams/:id',
component: TeamFormComponent,
pathMatch: 'full',
resolve: {
team: TeamFormTeamResolver,
resources: TeamFormResourcesResolver
},
canActivate: [AuthenticatedGuard]
}
]),
我的authGuard服务有一个canActivate方法,该方法只返回一个布尔值.
my authGuard service has a canActivate method which just returns a boolean.
public canActivate(): boolean {
if (this.authService.isLoggedIn()) {
return true;
}
this.router.navigate(['/logout', { redirect: location.pathname }]);
return false;
}
这是错误: 区域识别错误
我可以使用{enableTracing:true}获得路由器事件日志:
I could get a router event log with {enableTracing: true}:
Router Event: NavigationStart
Router Event: RoutesRecognized
Router Event: GuardsCheckStart
Router Event: GuardsCheckEnd
Router Event: ResolveStart
Router Event: NavigationError
推荐答案
感谢关注此问题的任何人.我得到了我问题的答案.
Thanks for anyone who looked at this issue. I got the answer to my question.
正如我所描述的,当我路由到详细信息页面时,我的解析器很少.在这些解析器之一中,有一种获取元素的逻辑.
As I described, I have few resolvers while I route to the detail page. On one of those resolvers there's a logic to get elements.
public resolve(_route: ActivatedRouteSnapshot, _state: RouterStateSnapshot): Observable<T[]> {
return this.service.browse({}).first();
}
https://stackoverflow.com/a/42346203/5162622 -如此处所述,first()为发送错误通知,因为没有值.因此,我将其替换为take(1),看起来一切都很好.
https://stackoverflow.com/a/42346203/5162622 - As mentioned here, the first() is sending error notification as there's no values. So I replaced it with take(1) and all looks good.
正如我在上面的评论中提到的,很高兴知道如何在路由时进行事件跟踪.这就是我可以追踪的方式.
As I mentioned above in the comment, it was good to know how to do event tracking while routing. That's how I could track this down.
这篇关于Angular2路由问题-区域感知错误顺序中没有元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!