AngularJS添加到浏览器的历史没有页面重载,无HTML5 pushState的 [英] AngularJS add to browser history without page reload and without HTML5 pushstate

查看:622
本文介绍了AngularJS添加到浏览器的历史没有页面重载,无HTML5 pushState的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个搜索页面,允许用户向下钻取到类别和/或输入检索词。我想给用户使用后退按钮撤消这些行动的能力。使用AngularJS,我怎么能有这样的网页条目添加到浏览器历史记录每一个动作。我不能使用HTML5 pushState的。

I have a search page that allows the user to drill-down into categories and/or enter search terms. I want to give the user the ability to use the back button to undo these actions. Using AngularJS, how can I have this page add entries to the browsers history for each of these actions. I cannot use HTML5 pushstate.

推荐答案

我发现我可以通过改变查询字符串参数,无需通过对答案重新加载页面做的 reloadOnSearch 的<一个href=\"http://stackoverflow.com/questions/17513093/how-can-i-set-a-query-parameter-in-angularjs-without-doing-a-route\">here:

I found I can do this by changing the query string parameters without reloading the page by using the answer about reloadOnSearch from here:

$routeProvider
  .when('/items', {
    controller: 'ItemsCtrl',
    templateUrl: '/templates/items',
    reloadOnSearch: false
  },
  ...
);

然后,从相同的答案,通过设置查询字符串:

And then, from that same answer, setting the query string using:

$location.search('id', 123);

通过回答<一个最后的检测路由变化 href=\"http://stackoverflow.com/questions/15093916/angularjs-watch-on-location-search-doesnt-work-when-reloadonsearch-is-false\">here:

And finally detecting route changes by using the answer from here:

$scope.$on('$routeUpdate', function(){
  $scope.sort = $location.search().sort;
  $scope.order = $location.search().order;
  $scope.offset = $location.search().offset;
});

这篇关于AngularJS添加到浏览器的历史没有页面重载,无HTML5 pushState的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆