Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular - Router navigate canceled without reason

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 :

Error

So the navigation is canceled without given reason. In others components, 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.

like image 605
Adam S Avatar asked Dec 08 '22 17:12

Adam S


1 Answers

Had 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 :)

like image 149
Keijo Tomiste Avatar answered Dec 10 '22 10:12

Keijo Tomiste