I want to enable HTML5 mode for my app. I have put the following code for the configuration, as shown 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
而如果我先go localhost:9000/
,然后点击一个按钮导航到/about
,我会得到:
Request URL:http://localhost:9000/views/about.html
这使得页面呈现得非常完美.
How can I enable angular to get the correct page when I refresh?