ngHref adds two history records in legacy browsers
Clicking on a link with ngHref directive in a legacy browser (IE8-9) will adds two records into browser history. There are need two clicks on back button to get back to previous page then.
Here is a sample application that will reproduce this behavior (needs to be run IE8-9): (sorry I didn't manage to create a working plunkr example)
"use strict";
var App = angular.module("App", ["ngRoute"]);
App.config(["$routeProvider", "$locationProvider", function ($routeProvider, $locationProvider) {
$routeProvider.when("/", {
controller: function ($scope) {
$scope.url = "/second";
},
template: "<a ng-href=\"{{url}}\">Click me!</a>"
});
$routeProvider.when("/second", {
template: "<h1>Now click on browser back button.</h1>"
});
$routeProvider.otherwise({redirectTo: "/"});
$locationProvider.html5Mode(true);
$locationProvider.hashPrefix("!");
}]);
I'm running AngularJS v1.2.15.
Can you please confirm this bahaviour?
Speaking of this, @tbosch should we backport the location fixes you wrote into 1.2.x? They still have the broken url parser on click. I would be willing to bet this issue is related to that.
Yes, we will. Just waiting a little longer for feeback...
can we verify if this still happens with 1.3.x? if it does let's look into it, otherwise let's close this as fixed.
Will look into this tomorrow...
Cannot reproduce on IE9 nor IE8 and Angular 1.2.15 nor latest in all of the following cases:
- without
tag: - loading from "/" or loading from "/index.html"
- with
tag
I used the following code (can't use plunker as the code listed above is meant to be run on /):
<!DOCTYPE html>
<html ng-app="App">
<head>
<!--
<script>document.write('<base href="'+location.href+'">');</script>
-->
<script src="https://code.angularjs.org/1.2.15/angular.js"></script>
<script src="https://code.angularjs.org/1.2.15/angular-route.js"></script>
<script>
var App = angular.module("App", ["ngRoute"]);
App.config(["$routeProvider", "$locationProvider", function ($routeProvider, $locationProvider) {
$routeProvider.when("/", {
controller: function ($scope) {
$scope.url = "/second";
},
template: "<a ng-href=\"{{url}}\">Click me!</a>"
});
$routeProvider.when("/second", {
template: "<h1>Now click on browser back button.</h1>"
});
$routeProvider.otherwise({redirectTo: "/"});
$locationProvider.html5Mode(true);
$locationProvider.hashPrefix("!");
}]);
App.run(function($location, $rootScope) {
$rootScope.$on('$locationChangeSuccess', function() {
console.log('$locationChangeSuccess');
});
});
</script>
</head>
<body>
<div ng-view></div>
</body>
</html>
Could you provide another reproduction case?
this is known to happen when iframes/objects are involved (which is obviously not showing up in the pasted code) --- iframes really screw up the history API
Hm, that is weird. I have tried everything to reproduce the bug again, but with no luck. It just works now.
I guess we can close this issues. If I run into this behavior again I will try to provide more information.
Thanks for the effort!
Closing as suggested...