You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
location.back() does not work on cancelled route #14645
Current behavior
I'm using a guard to protect a route (View Two). User can go from View One to View Two. Guard checks if application has some state. If not, the guard redirect the user on a dedicated page (View State). On that page user will give the expected state to application. After that, I do a location.back(). This calls send back the user on page View One not on View Two.
Expected behavior
I will like that 'location.back()' back to the cancelled route (View Two)
What is the motivation / use case for changing the behavior?
In my application, there are optional pages (optional functionalities). Those pages can be accessed only if some configurations has been done before. When users try to navigate to those pages for the first time, I redirect them to the configuration pages. On those configuration pages, I want to use 'location.back()' to back to the cancelled routes.
Please tell us about your environment:
Environment: Windows 7, Atom, npm, Webpack-dev-server
I took a deep dive into the router in order to track down what causes this and I found some things. Just not sure how to fix this but thought I could share my findings already.
So, the guards are executed right here. So when navigating to views/two, shouldActivate is false.
So then the router goes to the next check, which is the preActivationResolveData step. But at that point, this check kicks in. The navigationId is incremented already. The reason for this is quite simple, at that point, your guard initiated a new navigation which in turns triggers scheduleNavigation which on his turn increments the navigation id.
this.router.navigate(['/views/state']);
So what I tried to do, just to check if it worked, was calling location.pushState() right here. It calls pushState correctly but location.back() still redirects to views/one.
Activity
SamVerschueren commentedon Mar 17, 2017
I took a deep dive into the router in order to track down what causes this and I found some things. Just not sure how to fix this but thought I could share my findings already.
So, the guards are executed right here. So when navigating to
views/two,shouldActivateisfalse.So then the router goes to the next check, which is the preActivationResolveData step. But at that point, this check kicks in. The
navigationIdis incremented already. The reason for this is quite simple, at that point, your guard initiated a new navigation which in turns triggersscheduleNavigationwhich on his turn increments the navigation id.So what I tried to do, just to check if it worked, was calling
location.pushState()right here. It callspushStatecorrectly butlocation.back()still redirects toviews/one.atscott commentedon May 26, 2020
Duplicate of #13586
angular-automatic-lock-bot commentedon Jun 26, 2020
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.