admin管理员组文章数量:1241160
I have an angular (4.2.5) app, and at some point in my code, I do this :
this._appService
.post('/createhero/save', opts)
.subscribe(
(resData: any) =>
{
this._router.navigate(['home']);
}
);
The router call to navigate()
doesn't work - nothing happens. I enabled route debug, and this is what I get :
So the navigation is canceled without given reason. In others ponents, I have the same kind of navigate()
(some in observable callbacks too) which works well. The route /home
works as well.
I'm starting to run out of ideas, and I don't even know why the navigate()
won't work in this case.
I have an angular (4.2.5) app, and at some point in my code, I do this :
this._appService
.post('/createhero/save', opts)
.subscribe(
(resData: any) =>
{
this._router.navigate(['home']);
}
);
The router call to navigate()
doesn't work - nothing happens. I enabled route debug, and this is what I get :
So the navigation is canceled without given reason. In others ponents, I have the same kind of navigate()
(some in observable callbacks too) which works well. The route /home
works as well.
I'm starting to run out of ideas, and I don't even know why the navigate()
won't work in this case.
- Where did you use your navigate code? – TheUnreal Commented Jul 7, 2017 at 14:56
-
In my CreateHeroComponent save() method, which is triggered by a button
<button (click)="save()">Done</button>
– Adam S Commented Jul 7, 2017 at 15:03 -
For me, the issue was ing from a guard as well (the
MsalGuard
one from@azure/[email protected]
) and was only occurring at initial navigation on small-name routes like "/foo" (a bug from@azure/msal-angular
; in particular, the problem disappeared by renaming the route to "/foo-bar-baz") – fservantdev Commented Nov 24, 2021 at 17:29
1 Answer
Reset to default 17Had similar issue, reason
really doesn't help does it :)
What my issue was, was that the route I tried to navigate had a guard on its own which subscribed to observable and since I already gave value to it, the initial value of observable was false
and since route was blocked, navigation was canceled.
Can it be that some other guard is blocking the route and canActivate()
gives out true
/false
while depending on your query result but not actually waiting for the result?
Hope this helps a bit at debugging :)
本文标签: javascriptAngularRouter navigate canceled without reasonStack Overflow
版权声明:本文标题:javascript - Angular - Router navigate canceled without reason - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1740078894a2223409.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论