1

AngularJS 部分:

myApp.config(['$routeProvider','$locationProvider',function($routeProvider,$locationProvider) {
    $routeProvider.
    when('/main', {templateUrl: 'sub/main.tpl', controller: MainCtrl}).
    when('/users', {templateUrl: 'sub/users.tpl', controller: UserCtrl}).
    otherwise({redirectTo: '/main'});
}]);

和我的 index.html

<a href="#/main">Main</a> | <a href="#/users">Display Users</a>
<div ng-view></div>

它工作得很好,但我遇到了哈希问题。

当我尝试使用锚时,即:

<a href="#test">test</a>

当我单击此锚点时,它正在调用主页。

当我们使用 ng-view 时是否有可能摆脱散列?

4

1 回答 1

0

啊,因为 AngularJS 会重新路由你的 url。尝试使用 ng-href,

<a ng-href="#test">test</a>

编辑:您可以尝试将锚的 id 更改为 angular url ..

于 2013-03-23T02:07:51.597 回答