一直处理我坚持的一些$ locationProvider问题。我有一个简单的单页面页面。但我收到以下错误:
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)
我的app.js文件非常简单......
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';
}
}
}
})
;
}
]);
我的index.html文件中设置了<base href="http://localhost/apps/uiv8/" />
。所以,当我注释掉$ locationProvider代码时,一切都在#mode中工作正常。我可以毫无问题地进入/#/ about等。只要我将$ locationProvider部件放回去,就没有了。
关于我的环境的更多信息......我们在这里有asp.net的MVC,而route.config正在执行{* url}将所有内容重定向到默认路由,我甚至走了至于使用url重写修改IIS以发送到默认值,但我仍然得到上面的解析错误。
那么,有人知道发生了什么事吗?
谢谢, 尼克
答案 0 :(得分:2)
在索引页面中添加基本标记,如:
<base href="/">
而不是:
<base href="http://localhost/apps/uiv8/" />
希望它能解决你的问题。
答案 1 :(得分:0)
确保IIS中的应用程序名称与基本标记中的应用程序名称相同
<base href='http://localhost/apps/uiv10'>
确保您的IIS名称为app / uiv10
或者你想要的任何组合,但它们必须是相同的。