ui-router: $locationProvider.html5Mode(true) broken

I used Express with no parameters to generate a quick server that will serve these 2 files:

angular.module('myApp', ['ui.router'])
.config(['$locationProvider', function($locationProvider) {

    $stateProvider
    .state('home', {
        url: '/',
        template: '<h1>Home</h1>'
    });

    $locationProvider.html5Mode(true);
}]);
<!DOCTYPE html>
<html ng-app="myApp" ng-strict-di>
<head>
    <title>Lunr Test</title>
    <base href="./">
</head>
<body>
    <nav>
        <ul>
            <li><a ui-sref="home">Home</a></li>
        </ul>
    </nav>

    <div ui-view></div>

    <script src="lib/angular.min.1.3.js"></script>
    <script src="lib/angular-ui-router.min.js"></script>

    <script src="app.js"></script>
</body>
</html>

Using UIRouter 0.2.14 and AngularJS 1.3.16 and I get this error twice in console:

TypeError: Cannot read property 'replace' of undefined
    at Gb (angular.min.1.3.js:94)
    at Re.$get (angular.min.1.3.js:100)
    at Object.e [as invoke] (angular.min.1.3.js:36)
    at angular.min.1.3.js:38
    at d (angular.min.1.3.js:36)
    at Object.e [as invoke] (angular.min.1.3.js:36)
    at angular.min.1.3.js:38
    at d (angular.min.1.3.js:36)
    at Object.e [as invoke] (angular.min.1.3.js:36)
    at angular.min.1.3.js:38

Works normally when setting html5Mode to false, or when I comment that line.

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 16 (4 by maintainers)

Most upvoted comments

Still broken.

Quick fix:

  app.run(function ($browser) {
    $browser.baseHref = function () { return "/" };
  });