【发布时间】:2016-08-23 09:04:26
【问题描述】:
我使用 angular ui 路由,工作正常 - 但在不支持 html5mode 的浏览器中,它必须退回到 hashbang,链接不起作用。
www.test.com/something
www.test.com/#/something
不太确定如何使 hashbanged 链接起作用?
我绝望的尝试:
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'
}
);
【问题讨论】:
-
@CallumLinington 读了github.com/angular-ui/ui-router 文档,而docs.angularjs.org/guide/$location 没有运气;我
-
但是,如果您阅读该标题下的
$location service configuration,它会明确告诉您如何启用 hashbang 模式... -
是不是templateurl中的相对路径有问题?你的 html 中有基本标签吗?
-
是的,我脑子里有一个基本标签。指向 index.html
-
不应该指向“/”吗?