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

ngHref adds two history records in legacy browsers #8998

Closed
jirikuchta opened this issue Sep 9, 2014 · 9 comments
Closed

ngHref adds two history records in legacy browsers #8998

jirikuchta opened this issue Sep 9, 2014 · 9 comments

Comments

@jirikuchta
Copy link

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?

@caitp
Copy link
Contributor

caitp commented Sep 9, 2014

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.

@tbosch
Copy link
Contributor

tbosch commented Sep 9, 2014

Yes, we will. Just waiting a little longer for feeback...

@tbosch tbosch self-assigned this Sep 9, 2014
@tbosch tbosch added this to the 1.3.0 milestone Sep 9, 2014
@IgorMinar
Copy link
Contributor

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.

@tbosch
Copy link
Contributor

tbosch commented Oct 2, 2014

Will look into this tomorrow...

@tbosch
Copy link
Contributor

tbosch commented Oct 3, 2014

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>

@tbosch
Copy link
Contributor

tbosch commented Oct 3, 2014

Could you provide another reproduction case?

@tbosch tbosch modified the milestones: Purgatory, 1.3.0-rc.5 Oct 3, 2014
@caitp
Copy link
Contributor

caitp commented Oct 3, 2014

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

@jirikuchta
Copy link
Author

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!

@tbosch
Copy link
Contributor

tbosch commented Oct 8, 2014

Closing as suggested...

@tbosch tbosch closed this as completed Oct 8, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants