首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >hashbang urls不工作

hashbang urls不工作
EN

Stack Overflow用户
提问于 2016-04-28 14:16:52
回答 2查看 742关注 0票数 0

我使用角度ui路由,工作正常-但在不支持html5mode的浏览器中,它必须回到hashbang,链接不起作用。

www.test.com/something < works

www.test.com/#/something <不工作。(重定向到test.com)

不太确定如何使散列链接工作?

我绝望的尝试:

代码语言:javascript
复制
if (window.history && window.history.pushState) {
  // HTML5 history API is available.
  $locationProvider.html5Mode({
    enabled: true,
});
} else {
    // hashbang mode.
    window.location.hash = '/'; 
    $locationProvider.html5Mode({
      enabled: true,
    });
  }

$urlRouterProvider.otherwise("/");

$stateProvider
  .state('statistics', {
      url: "/statistics/:id",
      templateUrl: '../path/statistics.html',
      controller: 'ResultCtrl'
    }
);
EN

回答 2

Stack Overflow用户

发布于 2016-04-28 14:28:58

你只需要这样做:

代码语言:javascript
复制
$locationProvider.html5Mode({
    enabled: true,
}).hashPrefix("#");
票数 1
EN

Stack Overflow用户

发布于 2016-04-28 14:23:53

您启用了html5mode。这种模式基本上意味着站点不使用hashbang urls进行路由。我不认为你能同时支持。

删除以下代码:

代码语言:javascript
复制
$locationProvider.html5Mode({
  enabled: true,
});

更新

https://docs.angularjs.org/guide/$location#html5 5-模式

根据不需要测试推送状态支持的文档,如果不支持它,它会自动返回到hashbang。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36917384

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档