Reloading the page gives wrong GET request with AngularJS HTML5 mode

前端 未结 24 2903
慢半拍i
慢半拍i 2020-11-22 01:39

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\',\'$location         


        
24条回答
  •  爱一瞬间的悲伤
    2020-11-22 01:53

    I'm answering this question from the larger question:

    When I add $locationProvider.html5Mode(true), my site will not allow pasting of urls. How do I configure my server to work when html5Mode is true?

    When you have html5Mode enabled, the # character will no longer be used in your urls. The # symbol is useful because it requires no server side configuration. Without #, the url looks much nicer, but it also requires server side rewrites. Here are some examples:

    For Express Rewrites with AngularJS, you can solve this with the following updates:

    app.get('/*', function(req, res) {
    res.sendFile(path.join(__dirname + '/public/app/views/index.html'));
    });
    

    and

    
    
    

    and

    app.use('/',express.static(__dirname + '/public'));
    

提交回复
热议问题