Angularjs 角度ui路由-避免hashbang模式。ie9
我试图让HTML5模式,角度用户界面路由在IE9中工作Angularjs 角度ui路由-避免hashbang模式。ie9,angularjs,internet-explorer,angular-ui-router,angular-routing,Angularjs,Internet Explorer,Angular Ui Router,Angular Routing,我试图让HTML5模式,角度用户界面路由在IE9中工作 if (window.history && window.history.pushState) { $locationProvider.html5Mode(true); } else { console.log('IE9'); window.location.hash = '/'; // IE 9 FIX $locationProvider.html5Mode(true)
if (window.history && window.history.pushState) {
$locationProvider.html5Mode(true);
} else {
console.log('IE9');
window.location.hash = '/'; // IE 9 FIX
$locationProvider.html5Mode(true);
}
$urlRouterProvider.otherwise("/");
$stateProvider
.state('placeholder', {
url: "/path/:myId",
templateUrl: '../path.html
controller: 'ResultCtrl'
}
);
我得到的不是index/path/myid,而是index/#/index/myid,这会将我带到索引,因为浏览器会忽略哈希标记及其后的所有内容。(适用于firefox、chrome、edge、IE11-10(支持HTML5模式/api历史记录的浏览器))除了使用UI路由器,我的应用程序中还有以下内容: $locationProvider是Angular核心的一部分,用于配置应用程序的路径。默认情况下,角度前缀以#!,称为Hashbang模式。这是一个显示页面加载由JavaScript触发的约定 我将以下代码添加到app/scripts/app.js文件中的配置函数中 将以下代码添加到config函数:
(function() {
function config($stateProvider, $locationProvider) {
$locationProvider
.html5Mode({
enabled: true,
requireBase: false
});
}
通过将html5Mode方法的enabled属性设置为true,hashbang URL被禁用;也就是说,用户将看到没有hashbang的干净URL。将requireBase属性设置为false与hashbang问题无关,但这是避免常见$location错误的一种方法。您是否指定了应用程序的基本url?这是您的错误:?@MaKCbIMKo是的,我的头部有基本url。@Drgorosos不是真的,我被重定向到hashtag之前的任何内容,而不是空白页。