been dealing with some $locationProvider issues that I am stuck on. I've got a simple single page page. But I'm getting the following error:
TypeError: Cannot read property 'replace' of undefined
at trimEmptyHash (angular.js:10551)
at Object.$locationWatch (angular.js:11399)
at Scope.$get.Scope.$digest (angular.js:14217)
at Scope.$get.Scope.$apply (angular.js:14488)
at bootstrapApply (angular.js:1449)
at Object.invoke (angular.js:4182)
at doBootstrap (angular.js:1447)
at bootstrap (angular.js:1467)
at angularInit (angular.js:1361)
at HTMLDocument.<anonymous> (angular.js:26065)
My app.js file is pretty simple...
var app = angular.module('app',
[
'ui.router'
]
);
app.config([
'$stateProvider',
'$httpProvider',
'$locationProvider',
'$urlRouterProvider',
function ($stateProvider, $httpProvider, $locationProvider, $urlRouterProvider) {
$locationProvider.hashPrefix('!');
$locationProvider.html5Mode(true);
$stateProvider
.state('home',
{
url: '/',
views: {
'aboutView':
{
template: function (params) {
console.log("home");
return 'home';
}
}
}
})
.state('about',
{
url: '/about',
views: {
'aboutView':
{
template: function (params) {
console.log('about')
return 'about';
}
}
}
})
;
}
]);
I do have the <base href="http://localhost/apps/uiv8/" />
set in my index.html file. So, when I comment out the $locationProvider code, everything works fine in # mode. I can get to /#/about, etc. without issue. As soon as I put the $locationProvider parts back in, nothing.
A little bit more about my environment.... We do have asp.net's MVC in here, and the route.config is doing a {*url} to redirect all to the default route, and I've even gone as far as modifying IIS with url rewrites to send to the default, but I still get the parse Error above.
So, anybody got any ideas what's going on?
Thanks, Nick
If you do no want to specify a base tag, configure $locationProvider to not require a base tag by passing a definition object with requireBase:false to $locationProvider.html5Mode () like this: In order to support direct loading of HTML5 URLs, you need to enabler server-side URL rewriting.
The default value for the prefix is '!'. If boolean, sets html5Mode.enabled to value. If object, sets enabled, requireBase and rewriteLinks to respective values.
If enabled and requireBase are true, and a base tag is not present, an error will be thrown when $location is injected. See the $location guide for more information rewriteLinks - {boolean|string} - (default: true) When html5Mode is enabled, enables/disables URL rewriting for relative links.
rewriteLinks - {boolean|string} - (default: true) When html5Mode is enabled, enables/disables URL rewriting for relative links. If set to a string, URL rewriting will only happen on links with an attribute that matches the given string. For example, if set to 'internal-link', then the URL will only be rewritten for <a internal-link> links.
Add the base tag in your index page like :
<base href="/">
Instead of :
<base href="http://localhost/apps/uiv8/" />
Hope it will solve your problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With