Reloading the page gives wrong GET request with AngularJS HTML5 mode

前端 未结 24 2906
慢半拍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:50

    I have found even better Grunt plugin, that works if you have your index.html and Gruntfile.js in the same directory;

    https://npmjs.org/package/grunt-connect-pushstate
    

    After that in your Gruntfile:

     var pushState = require('grunt-connect-pushstate/lib/utils').pushState;
    
    
        connect: {
        server: {
          options: {
            port: 1337,
            base: '',
            logger: 'dev',
            hostname: '*',
            open: true,
            middleware: function (connect, options) {
              return [
                // Rewrite requests to root so they may be handled by router
                pushState(),
                // Serve static files
                connect.static(options.base)
              ];
            }
          },
        }
    },
    

提交回复
热议问题