Repository: angular
Issue: Angular Router + Browser History=> extra page view count in GA 
Labels: type: bug/fix,freq2: medium,area: router,state: confirmed,P3

<!--
PLEASE HELP US PROCESS GITHUB ISSUES FASTER BY PROVIDING THE FOLLOWING INFORMATION.

ISSUES MISSING IMPORTANT INFORMATION MAY BE CLOSED WITHOUT INVESTIGATION.
-->

## I'm submitting a...
<!-- Check one of the following options with "x" -->
<pre><code>
[ ] Regression (a behavior that used to work and stopped working in a new release)
[X] Bug report  <!-- Please search GitHub for a similar issue or PR before submitting -->
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
</code></pre>

## Current behavior
<!-- Describe how the issue manifests. -->
There is two bug here. one of them is already raised https://github.com/angular/angular/issues/17148

the other one is if resolver reject, Router will add the route to browser.history

## Expected behavior
<!-- Describe what the desired behavior would be. -->
rejected route should not be added to history by replaceState nor pushState becuse it is rejected and the user should stay in current page

## Minimal reproduction of the problem with instructions
<!--
For bug reports please provide the *STEPS TO REPRODUCE* and if possible a *MINIMAL DEMO* of the problem via
https://plnkr.co or similar (you can use this template as a starting point: http://plnkr.co/edit/tpl:AvJOMERrnz94ekVua0u5).
-->
http://plnkr.co/edit/PlUgiNrC8eTWUajoxxEg?p=preview

please open console.
you will land on page 1 by default
page 2 and 3 has a resolver which will reject. so you are not able to navigate to page 2 or 3

click on page2 or page3 link

an error will be raised (reproduce of issue 17148)
before each error, you will see a warning in console
`app.ts:92 >>>>THEY DID IT replaceState!` (reproduce this error)
 

## What is the motivation / use case for changing the behavior?
<!-- Describe the motivation or the concrete use case. -->
In single page application + GTM, we should track the page view event for GA by using browser.history
browser history change event will be fired after replaceState and/or pushState

because replaceState is called, GTM will fire page track event which is wrong.

## Environment

<pre><code>
Angular version: 4.1.2 - 4.3.2
<!-- Check whether this is still an issue in the most recent Angular version -->

Browser:
- [ ] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [X] Chrome (iOS) Version 59.0.3071.115 (Official Build) (64-bit)
- [X] Firefox version 54.0.1 (64-bit)
- [ ] Safari (desktop) version XX
- [X] Safari (iOS) Version 10.1.2 (12603.3.8)
- [ ] IE version XX
- [ ] Edge version XX
 
For Tooling issues:
- Node version: XX  <!-- run `node --version` -->
- Platform:  <!-- Mac, Linux, Windows -->

Others:
<!-- Anything else relevant?  Operating system version, IDE, package manager, HTTP server, ... -->
</code></pre>
I am not sure it is relevant or not so I am putting it in other section:
base on my comment on another issue if you modify resolver and replace error line with following:
`subject.error({message: 'some error', ngNavigationCancelingError: true});`
there will be no error any more
but the problem in this error will be bigger.
replaceState will be fired twice!!!! for each rejected route!!!!

issue https://github.com/angular/angular/issues/13873 is similar to issue 1
the main expectation is wrong but still it is raised becuse resolver reject will raise an error