Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

revert: fix($browser): don’t use history api when only the hash changes #9423

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions src/ng/browser.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
'use strict';
/* global stripHash: true */

/**
* ! This is a private undocumented service !
Expand Down Expand Up @@ -154,13 +153,8 @@ function Browser(window, document, $log, $sniffer) {
// setter
if (url) {
if (lastBrowserUrl == url) return;
var sameBase = lastBrowserUrl && stripHash(lastBrowserUrl) === stripHash(url);
lastBrowserUrl = url;
// Don't use history API if only the hash changed
// due to a bug in IE10/IE11 which leads
// to not firing a `hashchange` nor `popstate` event
// in some cases (see #9143).
if (!sameBase && $sniffer.history) {
if ($sniffer.history) {
if (replace) history.replaceState(null, '', url);
else {
history.pushState(null, '', url);
Expand Down
3 changes: 0 additions & 3 deletions src/ng/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -720,9 +720,6 @@ function $LocationProvider(){

if (absHref && !elm.attr('target') && !event.isDefaultPrevented()) {
if ($location.$$parseLinkUrl(absHref, relHref)) {
// We do a preventDefault for all urls that are part of the angular application,
// in html5mode and also without, so that we are able to abort navigation without
// getting double entries in the location history.
event.preventDefault();
// update location manually
if ($location.absUrl() != $browser.url()) {
Expand Down
22 changes: 0 additions & 22 deletions test/ng/browserSpecs.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,17 +445,6 @@ describe('browser', function() {
expect(locationReplace).not.toHaveBeenCalled();
});

it('should set location.href and not use pushState when the url only changed in the hash fragment to please IE10/11', function() {
sniffer.history = true;
browser.url('http://server/#123');

expect(fakeWindow.location.href).toEqual('http://server/#123');

expect(pushState).not.toHaveBeenCalled();
expect(replaceState).not.toHaveBeenCalled();
expect(locationReplace).not.toHaveBeenCalled();
});

it('should use location.replace when history.replaceState not available', function() {
sniffer.history = false;
browser.url('http://new.org', true);
Expand All @@ -467,17 +456,6 @@ describe('browser', function() {
expect(fakeWindow.location.href).toEqual('http://server/');
});

it('should use location.replace and not use replaceState when the url only changed in the hash fragment to please IE10/11', function() {
sniffer.history = true;
browser.url('http://server/#123', true);

expect(locationReplace).toHaveBeenCalledWith('http://server/#123');

expect(pushState).not.toHaveBeenCalled();
expect(replaceState).not.toHaveBeenCalled();
expect(fakeWindow.location.href).toEqual('http://server/');
});

it('should return $browser to allow chaining', function() {
expect(browser.url('http://any.com')).toBe(browser);
});
Expand Down