问题描述
一直在处理我遇到的一些 $locationProvider 问题.我有一个简单的单页页面.但我收到以下错误:
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)
我的 app.js 文件非常简单...
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';
}
}
}
})
;
}
]);
我确实在 index.html 文件中设置了 <base href="http://localhost/apps/uiv8/"/>
.因此,当我注释掉 $locationProvider 代码时,在 # 模式下一切正常.我可以毫无问题地访问/#/about 等.一旦我把 $locationProvider 部分放回去,什么都没有.
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.
多一点关于我的环境....我们这里确实有asp.net的MVC,并且route.config正在做一个{*url}来重定向所有到默认路由,我什至已经走了至于使用 url 重写修改 IIS 以发送到默认值,但我仍然收到上面的解析错误.
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?
谢谢,尼克
推荐答案
在您的索引页面中添加基本标签,如:
Add the base tag in your index page like :
<base href="/">
代替:
<base href="http://localhost/apps/uiv8/" />
希望它能解决您的问题.
Hope it will solve your problem.
这篇关于$locationProvider.html5Mode(true) 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!