问题描述
我刚刚开始接触角,所以这可能是一个常见的错误新手,但我想达到以下URL格式:
I'm just starting out with Angular, so this might be a common newbie mistake but I am trying to achieve the following url format:
http://myapp.localhost/index.html#!/about
我相信这应该是角度的默认?
Which I believe should be the default for Angular?
这是我的配置:
angular.module('App', []).config(function($routeProvider, $locationProvider, VIEWS_ROOT) {
$locationProvider.html5Mode(false);
$locationProvider.hashPrefix = '!';
// Routing
$routeProvider.when('/', {templateUrl: './welcome.html', controller: 'WelcomeController'});
$routeProvider.when('/about', {templateUrl: './about.html', controller: 'AboutController'});
})
.run(function($rootScope) {
//...
});
在我的HTML我有一个简单的锚像这样:
In my html I have a simple anchor like so:
<a href="#!/about">About</a>
然而,当我点击锚,构造所产生的URL是:
However when I click that anchor, the resulting URL constructed is:
http://myapp.localhost/index.html#/!/about
这显然不符合我的任何路线......有点难倒什么实际发生在这里,或者说我做错了什么。我是一个虚拟主机下运行了我的本地Apache实例。没有什么用mod_rewrite的事情 - 所以它看起来像角是这样做的。
Which obviously fails to match any of my routes... a bit stumped on what's actually happening here, or what I'm doing wrong. I'm running off my local Apache instance under a vhost. There's nothing going on with mod_rewrite - so it looks like Angular is doing this.
推荐答案
这是设置散列preFIX,而不是一个性质的方法。 $ locationProvider.hash preFIX('!');
It's a method to set the hashPrefix, not a property. $locationProvider.hashPrefix('!');
这篇关于$位置哈希preFIX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!