[英]AngularJS 1.4.8 $locationProvider.html5Mode does not help to remove hash
I'm using AngularJS 1.4.8. 我正在使用AngularJS 1.4.8。 As it's sayed at the tutorial, I've created routing rules: 就像在教程中所说的那样,我已经创建了路由规则:
alphApp.config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) {
$routeProvider
.when('/', {
templateUrl: 'pages/home.html',
controller: 'mainCtrl'
})
.when('/alphabet', {
templateUrl: 'pages/alphabet.html',
controller: 'alhabetController'
})
.otherwise({
redirectTo: '/'
});
$locationProvider.html5Mode({
enabled: true,
requireBase: false
});
}]);
But when I press the link 但是当我按下链接
<a href="#alphabet">
The address bar shows domain/#alphabet and the content remains unchanged till I update the page. 地址栏显示域/#alphabet ,内容保持不变,直到我更新页面。 After the page update url becomes domain/alphabet with right content. 页面更新后,URL变成具有正确内容的域/字母 。 If I remove this part: 如果我删除此部分:
$locationProvider.html5Mode({
enabled: true,
requireBase: false
});
the url will look like domain/#/alphabet but content will change properly. 网址看起来像domain /#/ alphabet,但内容会正确更改。 The issue can be solved by downgrading angular to the 1.2.25 howerwer it causes issue with get-params, so is there a way to have pretty urls without downgrading angular? 可以通过将angular降级到1.2.25来解决此问题,这会导致get-params出现问题,那么有没有办法在不降低angular的情况下拥有漂亮的url?
Your href is telling the browser to go to oldpath/#alphabet, oldpath/alphabet. 您的href告诉浏览器转到oldpath /#alphabet,oldpath / alphabet。 You need to change your hrefs to: 您需要将hrefs更改为:
href="/alphabet"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.