Issue 1:
I'm submitting a ...

[x] bug report
[ ] feature request
[ ] support request

Current behavior

Returning false on CanDeactivate implementation influences browser history.

Seems to be leftover from #10321 and #12825

Expected behavior

Returning false on CanDeactivate implementation does not influence browser history.

Minimal reproduction of the problem with instructions

Present in Angular Routing Demo plnkr:

https://angular.io/resources/live-examples/router/ts/eplnkr.html

STEPS TO REPRODUCE:

Click "Crisis Center"

Click Crisis Center 1, then 2, then 3

Edit Crisis Center 3's "Name" in its details

Press browser "Back" button, and press "Cancel" when confirm dialog pops up asking if you want to discard changes

Press browser "Back" button again, but this time press "OK" when confirm dialog pops up asking if you want to discard changes

RESULT:

You are taken back to Crisis Center 1 detail view instead of Crisis Center 2. If you press browser "Forward" button twice, you'll notice that both times you are taken to Crisis Center 3 detail view. The Crisis Center 3 detail view has essentially replaced the Crisis Center 2 detail view history entry.

What is the motivation / use case for changing the behavior?

I press my browser's "Back" button but then choose to cancel navigation in order to first save pending changes. When I press my browser's "Back" button again, I should navigate to the previous page as if this was the first time I pressed my browser's "Back" button.

Please tell us about your environment:

-Angular demo plnkr (also present in my own ng-cli v1.0.0.24-beta environment)

-Windows 10 x64

Angular version: 2.4.1, Router 3.4.1

Browser: Chrome v55.0.2883.87 m (64-bit) (untested on others)

Language: TypeScript 2.0.10

Issue 2:
I'm submitting a ... (check one with "x")

[X ] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

Currently, I have a deactivation guard on a route which will return false or true depending on a condition. To get to this guarded route, the user must pass though 3 navigation step. Now, once on the guarded route, when using location.back(), the guard is called. If it returns true, the previous route is loaded. If the guard returns false, the navigation is cancelled. But if we redo a Location.back() after a failed navigation, the previous route that will be loaded will be 2 steps in the history instead of 1 (user perception).

Workflow

Main -- navigate to --> Route 1
Route 1 -- navigate to --> Route 2
Route 2 -- navigate to --> Route 3
Route 3 -- location.back() --> guard returns true --> Route 2
Route 2 -- navigate to --> Route 3
Route 3 -- location.back() --> guard returns false --> Route 3
Route 3 -- location.back() --> guard returns true --> Route 1 (should be Route 2)

Expected behavior

An expected behavior for a user would be that navigating back brings back to the previous routed page.

Workflow

Main -- navigate to --> Route 1
Route 1 -- navigate to --> Route 2
Route 2 -- navigate to --> Route 3
Route 3 -- location.back() --> guard returns true --> Route 2
Route 2 -- navigate to --> Route 3
Route 3 -- location.back() --> guard returns false --> Route 3
Route 3 -- location.back() --> guard returns true --> Route 2 (expected)

Minimal reproduction of the problem with instructions

Plnkr

Click button Nav to route1

Click button Nav to route2

Click button Nav to route3

Click button Block Nav Back

Click button Nav back

BOGUE: The location.back() routed on Route1 instead of Route2

Personnal investigation

After some investigation, I saw that in routerState$.then (router.ts line 752) this logic used when navigationIsSuccessful == false is pretty simply but it is the actual cause of this bug. Basically, when a deactivation guard is hit, the location of the browser is already changed to the previous route. Which means that when the guard returns false, the routerState$ runs his logic and calls resetUrlToCurrentUrlTree(). At this point we can see that we replace the state of the current location. But by doing this, we loose that route in the history which means that in my plunker, if we click the block nav back 3 times and then click the nav back we will actually kill the application.

What is the motivation / use case for changing the behavior?

This is for me a pretty big bug since a guard that returns false breaks alters the current routing history. In the case of our application this breaks the workflow and brings wrong business scopes to a user.

Please tell us about your environment:

Windows 10, NPM, Nodejs, Visual Studio 2015 (using nodejs for typescript compilation)

Angular version: 2.3.3

Browser: [ all ]

Language: [TypeScript 2.0.10 | ES5]