Reloading the page gives wrong GET request with AngularJS HTML5 mode

前端 未结 24 2977
慢半拍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 02:07

    I had a similar problem and I solved it by:

    • Using in the index page

    • Using a catch all route middleware in my node/Express server as follows (put it after the router):

    app.use(function(req, res) {
        res.sendfile(__dirname + '/Public/index.html');
    });
    

    I think that should get you up and running.

    If you use an apache server, you might want to mod_rewrite your links. It is not difficult to do. Just a few changes in the config files.

    All that is assuming you have html5mode enabled on angularjs. Now. note that in angular 1.2, declaring a base url is not recommended anymore actually.

提交回复
热议问题