Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
AngularJS-如何停止<;基地>;标签+;HTML5模式+$阻止锚定标记链接刷新网页的位置_Angularjs - Fatal编程技术网

AngularJS-如何停止<;基地>;标签+;HTML5模式+$阻止锚定标记链接刷新网页的位置

AngularJS-如何停止<;基地>;标签+;HTML5模式+$阻止锚定标记链接刷新网页的位置,angularjs,Angularjs,这是我的JS(我将html5Mode设置为True,我正在使用$http$window和$location: .config(['$locationProvider', function($locationProvider){ $locationProvider.html5Mode(true); // Important. Needed for URLs. }]) .controller("MainCtrl", ["$http", "$window", "$location", fun

这是我的JS(我将html5Mode设置为True,我正在使用
$http$window
$location

.config(['$locationProvider', function($locationProvider){
    $locationProvider.html5Mode(true); // Important. Needed for URLs.
}])

.controller("MainCtrl", ["$http", "$window", "$location", function($http, $window, $location) {
还将设置基本标记,如下所示:

<base href="/">
<li><a href="/" target='_self'>Home &#x25BC;</a></li>

这是我的html页面:

<div>
    <ul class="nav nav-pills">
        <li><a href="/">Home &#x25BC;</a></li>
        <li><a href='/post'>Post</a></li>
        <li><a href="/settings">Settings</a></li>
        <li><a href ng-click="ctrl.logoutUser()">Logout</a></li>
    </ul>
</div>


问题是,当我点击任何链接时,URL会更新,但页面不会刷新。如果我从我的控制器中删除
$location
,它就会正常工作,但我需要
$location
从我的JS中获取URL以用于其他目的。有没有办法阻止AngularJS阻止刷新网页?

一种解决方案ion将向锚定标记添加
target=''u self'
,如下所示:

<base href="/">
<li><a href="/" target='_self'>Home &#x25BC;</a></li>

  • 答案取自这篇SO帖子:

    对于那些使用ui路由器的人,请始终尝试使用

    ui-sref="stateName.childState"
    
    这将防止重新加载问题,而不是href=“myurl”

    参考: