此链接无法在我的angularjs onepage应用中的所有浏览器中使用。
<a href="/">homepage</a>
根据浏览器的不同,网址会有所不同。在某些浏览器中,网址以尾部“/#”结尾,其他网址以“/#/”结尾,例如“http://localhost/#”和“http://localhost/#/”。这意味着在非IE浏览器中以/#结尾的请求无法加载ViewA
这是我的路线提供者:
mainApp.config(["$routeProvider",
function ($routeProvider) {
$routeProvider
.when("/", {
templateUrl: "Views/ViewA.html"
})
.when("/home", {
templateUrl: "Views/ViewB.html"
})
.otherwise({
redirectTo: "/"
});
}]);
有没有办法让浏览器的行为相同?一个库可供参考? 我唯一的参考呃: angular.js 角route.js
答案 0 :(得分:1)
我说你的主播应该是:
<a href="/#/">homepage</a>
答案 1 :(得分:1)
答案 2 :(得分:0)
添加一个html5mode设置为true的locationProvider,似乎解决了我的问题
mainApp.config(["$locationProvider", "$routeProvider",
function ($locationProvider, $routeProvider) {
$locationProvider.html5Mode(true);
$routeProvider
.when("/", {
templateUrl: "Views/ViewA.html"
})
.when("/home", {
templateUrl: "Views/ViewB.html"
})
.otherwise({
redirectTo: "/"
});
}]);