Reloading the page gives wrong GET request with AngularJS HTML5 mode

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

    I wrote a simple connect middleware for simulating url-rewriting on grunt projects. https://gist.github.com/muratcorlu/5803655

    You can use like that:

    module.exports = function(grunt) {
      var urlRewrite = require('grunt-connect-rewrite');
    
      // Project configuration.
      grunt.initConfig({
        connect: {
          server: {
            options: {
              port: 9001,
              base: 'build',
              middleware: function(connect, options) {
                // Return array of whatever middlewares you want
                return [
                  // redirect all urls to index.html in build folder
                  urlRewrite('build', 'index.html'),
    
                  // Serve static files.
                  connect.static(options.base),
    
                  // Make empty directories browsable.
                  connect.directory(options.base)
                ];
              }
            }
          }
        }
      })
    };
    

提交回复
热议问题