【发布时间】:2013-05-10 07:23:17
【问题描述】:
我想为我的应用启用 HTML5 模式。我已经放了如下代码进行配置,如图here:
return app.config(['$routeProvider','$locationProvider', function($routeProvider,$locationProvider) {
$locationProvider.html5Mode(true);
$locationProvider.hashPrefix = '!';
$routeProvider.when('/', {
templateUrl: '/views/index.html',
controller: 'indexCtrl'
});
$routeProvider.when('/about',{
templateUrl: '/views/about.html',
controller: 'AboutCtrl'
});
如您所见,我使用了$locationProvider.html5mode,并更改了ng-href 的所有链接以排除/#/。
问题
目前,我可以转到localhost:9000/ 并查看索引页面并导航到其他页面,例如localhost:9000/about。
但是,当我刷新localhost:9000/about 页面时会出现问题。我得到以下输出:Cannot GET /about
如果我查看网络调用:
Request URL:localhost:9000/about
Request Method:GET
如果我先转到localhost:9000/,然后单击导航到/about 的按钮,我会得到:
Request URL:http://localhost:9000/views/about.html
完美呈现页面。
如何在刷新时启用 Angular 以获取正确的页面?
【问题讨论】:
标签: angularjs html angular-routing