【问题标题】:AngularJS + html5Mode + custom fallbackAngularJS + html5Mode + 自定义后备
【发布时间】:2013-11-27 11:14:54
【问题描述】:

我有一个 html5Mode = true 的应用程序,但在 IE 上我不需要回退到 #/url。我需要的是保留 URL 并重新加载完整的页面。

如果我找不到任何方法,我将需要编辑 AngularJS 文件,而这正是我不想要的。

建议?

谢谢!

-- 编辑--

作为临时解决方案,我在 AngularJS 文件中注释了一些代码。

/*if ($sniffer.history) {*/
    $location = new LocationUrl(
      convertToHtml5Url(initUrl, basePath, hashPrefix),
      pathPrefix, appBaseUrl);
  /*} else {
    $location = new LocationHashbangInHtml5Url(
      convertToHashbangUrl(initUrl, basePath, hashPrefix),
      hashPrefix, appBaseUrl, basePath.substr(pathPrefix.length + 1));
  }*/

现在它不会回退到 Hashtag url,如果浏览器不支持历史 API,Browser.url 会生成一个 location.href

【问题讨论】:

  • 你看到我的回答了吗?你觉得有用吗?

标签: angularjs


【解决方案1】:

我认为这可以满足您的需求。如果不是,可能解决方案涉及相同的事件$locationChangeStart

  var gate = 1;
  $scope.$on("$locationChangeStart", function(event, nextLocation, currentLocation) {
    if ($('html').is('.ie6, .ie7, .ie8')) {
      if (gate === 0) { //prevent endless location change
        gate = 1;
        window.location.href = nextLocation; //reload the page
      }
      else {
        gate = 0;
      }
    }
  });

如果您不知道此 OldIE 检查,see this post.

【讨论】:

  • 这真的有效吗?不是所有的 URL 都包含哈希值吗?
猜你喜欢
  • 2015-08-21
  • 1970-01-01
  • 2015-02-16
  • 2014-09-10
  • 2014-10-05
  • 2013-11-06
  • 2014-12-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多