AngularJS-如何停止<;基地>;标签+;HTML5模式+$阻止锚定标记链接刷新网页的位置
这是我的JS(我将html5Mode设置为True,我正在使用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
$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 ▼</a></li>
这是我的html页面:
<div>
<ul class="nav nav-pills">
<li><a href="/">Home ▼</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 ▼</a></li>
答案取自这篇SO帖子:对于那些使用ui路由器的人,请始终尝试使用
ui-sref="stateName.childState"
这将防止重新加载问题,而不是href=“myurl”
参考: