使用AngularJSHTML 5模式重新加載頁面會產(chǎn)生錯誤的GET請求我想為我的應用程序啟用HTML 5模式。我已經(jīng)為配置放置了以下代碼,如下所示這里: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排除/#/.問題現(xiàn)在,我可以去localhost:9000/并查看索引頁并導航到其他頁面,如localhost:9000/about.但是,當我刷新localhost:9000/about一頁。我得到以下輸出:Cannot GET /about如果我看一下網(wǎng)絡呼叫:Request URL:localhost:9000/aboutRequest Method:GET如果我第一次去localhost:9000/然后單擊導航到/about我得到:Request URL:http://localhost:9000/views/about.html它完美地呈現(xiàn)了頁面。當我刷新時,如何啟用角獲取正確的頁面?
3 回答

慕桂英3389331
TA貢獻2036條經(jīng)驗 獲得超8個贊
使用 <base href="/index.html">
在索引頁中 在我的節(jié)點/快速服務器中使用CATCH所有路由中間件,如下所示(將其放在路由器后面):
app.use(function(req, res) { res.sendfile(__dirname + '/Public/index.html');});
- 3 回答
- 0 關注
- 696 瀏覽
添加回答
舉報
0/150
提交
取消