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

angular routing adding unwanted hash tags to URL #3083

Closed
jssebastian opened this issue Jun 27, 2013 · 2 comments
Closed

angular routing adding unwanted hash tags to URL #3083

jssebastian opened this issue Jun 27, 2013 · 2 comments

Comments

@jssebastian
Copy link

When using angular routing with a "/" route, an unwanted hash tag is added to the URL by angular. I cannot demonstrate this in a plunkr/jsfiddle, but if you put the page below on a server as test.html, and try to visit myserver.com/test.html, you get redirected to myserver.com/test.html#/test.html, and the page says "Hello test.html". Visiting test.html#/ works as expected and displays "Hello Dude".

Switching the link to angular 1.1.4 fixes the problem.

<html dir="ltr" lang="en-US">

<head>
  <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.js"></script>
  <script>
    angular.module('testPage',[])
      .controller('testCtrl',function($scope,$routeParams){
        $scope.name="Dude";
        if($routeParams.name){
          $scope.name=$routeParams.name;
        }
      })
      .config(function($routeProvider){
        $routeProvider
          .when('/:name',{
            template: '<div>Hello {{name}}</div>',
            controller: "testCtrl"
          })
          .when('/',{
            template: '<div>Hello {{name}}</div>',
            controller: "testCtrl"})
          .otherwise({
            template: 'No route!'
          });

      });
  </script>

</head>
<body ng-app="testPage">
  <div ng-view>
  </div>
</body>


</html>
@fessyfoo
Copy link

I believe this is the same issue as #2833 and #2860

@jssebastian
Copy link
Author

You're right! Did not find those for some reason. #2860 also has a more minimal example that triggers the bug just by injecting $location, while in the above example it was injected as a dependency of $routeParams.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants