NavigateByUrl不';t使用angular-oauth2-oidc从Ontoken接收工作

NavigateByUrl不';t使用angular-oauth2-oidc从Ontoken接收工作,angular,angular-oauth2-oidc,Angular,Angular Oauth2 Oidc,我使用的是angular-oauth2-oidc包,我使用的是隐式流,目前无法迁移到代码流 我想导航到原始网址时,流结束,我已经使用作为文件建议 我的问题是我无法从onTokenReceived功能导航,由navitageByUrl解决的承诺通过false解决,但控制台上没有错误: 导出类AppComponent{ url:string; 建造师( 专用oauthService:oauthService, 专用路由器(路由器){ this.url=window.location.pathname

我使用的是
angular-oauth2-oidc
包,我使用的是隐式流,目前无法迁移到代码流

我想导航到原始网址时,流结束,我已经使用作为文件建议

我的问题是我无法从
onTokenReceived
功能导航,由
navitageByUrl
解决的承诺通过
false
解决,但控制台上没有错误:

导出类AppComponent{
url:string;
建造师(
专用oauthService:oauthService,
专用路由器(路由器){
this.url=window.location.pathname;//获取请求的url。
}
ngOnInit(){
this.oauthService.loadDiscoveryDocument()。然后(res=>{
控制台日志(res);
this.oauthService.tryLogin({
已接收到:(信息)=>{
//接收状态和导航到。
this.router.navigateByUrl(info.state).then(res=>{
如果(!res){
控制台错误(“在获取令牌“+res”后导航到“+info.state+”);
}
});
}
})。然后(res=>{
if(!res){//if not login init隐式流将url作为状态传递。
this.oauthService.initImplicitFlow(this.url);
}
})
})        
}
}
但是,如果使用
setTimeout
,在100毫秒后运行,则它可以工作:

onTokenReceived:(信息)=>{
//接收状态和导航到。
设置超时(()=>{
this.router.navigateByUrl(info.state).then(res=>{
如果(!res){
控制台错误(“在获取令牌“+res”后导航到“+info.state+”);
}
});
},100);//小于100时不工作。
}
有人能帮我吗?
为什么navigateByUrl不工作?

我一直在调试角度路由器,以了解为什么导航解析为false。我已经看到,如果其他导航启动,导航可以取消。嗯,我已经记录了路由器事件,我可以看到其他导航在导航过程中启动

这是日志:

app.component.ts:31 NAVEvent- NavigationStart to /#id_token=eyJhbG(...hide for simplicity...)8da3798eac66
app.component.ts:31 NAVEvent- RoutesRecognized
app.component.ts:31 NAVEvent- GuardsCheckStart
app.component.ts:31 NAVEvent- ChildActivationStart
app.component.ts:31 NAVEvent- ActivationStart
app.component.ts:31 NAVEvent- GuardsCheckEnd
app.component.ts:31 NAVEvent- ResolveStart
app.component.ts:31 NAVEvent- ResolveEnd
app.component.ts:31 NAVEvent- ActivationEnd
app.component.ts:31 NAVEvent- ChildActivationEnd
app.component.ts:31 NAVEvent- NavigationEnd
app.component.ts:31 NAVEvent- Scroll
app.component.ts:50 TOKEN RECEIVED --> Here I received the token and init the navigation to original requested URL
app.component.ts:31 NAVEvent- NavigationStart to /data/orderByToken/f5c2a1af-b0fa-48ab-867d-d748f53d42fb
app.component.ts:31 NAVEvent- RouteConfigLoadStart
app.component.ts:31 NAVEvent- NavigationCancel   --> this cancel my navigation and causes false resolved.
app.component.ts:31 NAVEvent- NavigationStart to /welcome -> Angular navigate to /welcome due to I have a redirect on routing module.
app.component.ts:31 NAVEvent- RoutesRecognized
app.component.ts:31 NAVEvent- GuardsCheckStart
app.component.ts:31 NAVEvent- GuardsCheckEnd
app.component.ts:31 NAVEvent- ActivationEnd
app.component.ts:31 NAVEvent- ChildActivationEnd
app.component.ts:31 NAVEvent- NavigationEnd
app.component.ts:31 NAVEvent- Scroll
我在angular route配置中有一个重定向,如下所示:

{ path:"", redirectTo: "welcome", pathMatch: "full"}{ path:"", redirectTo: "welcome", pathMatch: "full"}
不是一个角度oauth2-oidc问题

当导航承诺用false解决时,导航到/欢迎的操作完成,因此我决定再试一次,下次运行导航,这一次有效

比如:

this.router.navigateByUrl(state).then(res=>{
如果(!res){
this.router.navigateByUrl(状态);
}
});
因为如果导航失败会引发异常,只有当承诺为false时,才会毫无例外地由于另一个导航而取消您的导航


这就解决了我的问题。

我一直在调试角度路由器,以了解为什么导航会以false解决。我已经看到,如果其他导航启动,导航可以取消。嗯,我已经记录了路由器事件,我可以看到其他导航在导航过程中启动

这是日志:

app.component.ts:31 NAVEvent- NavigationStart to /#id_token=eyJhbG(...hide for simplicity...)8da3798eac66
app.component.ts:31 NAVEvent- RoutesRecognized
app.component.ts:31 NAVEvent- GuardsCheckStart
app.component.ts:31 NAVEvent- ChildActivationStart
app.component.ts:31 NAVEvent- ActivationStart
app.component.ts:31 NAVEvent- GuardsCheckEnd
app.component.ts:31 NAVEvent- ResolveStart
app.component.ts:31 NAVEvent- ResolveEnd
app.component.ts:31 NAVEvent- ActivationEnd
app.component.ts:31 NAVEvent- ChildActivationEnd
app.component.ts:31 NAVEvent- NavigationEnd
app.component.ts:31 NAVEvent- Scroll
app.component.ts:50 TOKEN RECEIVED --> Here I received the token and init the navigation to original requested URL
app.component.ts:31 NAVEvent- NavigationStart to /data/orderByToken/f5c2a1af-b0fa-48ab-867d-d748f53d42fb
app.component.ts:31 NAVEvent- RouteConfigLoadStart
app.component.ts:31 NAVEvent- NavigationCancel   --> this cancel my navigation and causes false resolved.
app.component.ts:31 NAVEvent- NavigationStart to /welcome -> Angular navigate to /welcome due to I have a redirect on routing module.
app.component.ts:31 NAVEvent- RoutesRecognized
app.component.ts:31 NAVEvent- GuardsCheckStart
app.component.ts:31 NAVEvent- GuardsCheckEnd
app.component.ts:31 NAVEvent- ActivationEnd
app.component.ts:31 NAVEvent- ChildActivationEnd
app.component.ts:31 NAVEvent- NavigationEnd
app.component.ts:31 NAVEvent- Scroll
我在angular route配置中有一个重定向,如下所示:

{ path:"", redirectTo: "welcome", pathMatch: "full"}{ path:"", redirectTo: "welcome", pathMatch: "full"}
不是一个角度oauth2-oidc问题

当导航承诺用false解决时,导航到/欢迎的操作完成,因此我决定再试一次,下次运行导航,这一次有效

比如:

this.router.navigateByUrl(state).then(res=>{
如果(!res){
this.router.navigateByUrl(状态);
}
});
因为如果导航失败会引发异常,只有当承诺为false时,才会毫无例外地由于另一个导航而取消您的导航

这解决了我的问题