This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
$location.absUrl() returns undefined with base href and html5Mode #11091
Closed
Description
Running Angular 1.3.13
base href to load all assets from a specific subdirectory
<base href="/marketing/" />
enable html 5 mode
// remove hash /#/
$locationProvider.html5Mode(true);
Routes are setup like this:
$routeProvider
.when('/', {
templateUrl: 'views/main.html',
controller: 'MainCtrl'
})
.when('/about', {
templateUrl: 'views/about.html',
controller: 'AboutCtrl'
})
.otherwise({
redirectTo: '/'
});
Upon loading the application, the following error is thrown n times (I believe per anchor href on the page)
2VM9729 angular.js:11607 TypeError: Cannot read property 'replace' of undefined
at trimEmptyHash (VM9729 angular.js:10564)
at $LocationProvider.$get (VM9729 angular.js:11374)
at Object.invoke (VM9729 angular.js:4185)
at VM9729 angular.js:4003
at getService (VM9729 angular.js:4144)
at Object.invoke (VM9729 angular.js:4176)
at VM9729 angular.js:4003
at getService (VM9729 angular.js:4144)
at Object.invoke (VM9729 angular.js:4176)
at VM9729 angular.js:6485
Debugging this issue, I found at this line:
// rewrite hashbang url <> html5 url
if (trimEmptyHash($location.absUrl()) != trimEmptyHash(initialUrl)) {
$browser.url($location.absUrl(), true);
}
$location.absUrl()
returns undefined
My GUESS is that the base href is throwing off the matching of routes at $.when('/'), and so is undefined...