Grunt URL rewrite in Angular application on page reload

这一生的挚爱 提交于 2020-01-03 07:57:06

问题


Here's what the livereload block looks like in Grunt file:

livereload: {
  options: {
    open: true,
    middleware: function(connect, options, middleware) {
      var optBase = typeof options.base === "string" 
        ? [options.base] 
        : options.base;

      return [
        [
          require("connect-modrewrite")(["!(\\..+)$ / [L]"])
        ].concat(
          optBase.map(function(path) { return connect.static(path); })
        ),
        connect.static(".tmp"),
        connect().use("/bower_components", connect.static("./bower_components")),
        connect().use("/app/styles", connect.static("./app/styles")),
        connect.static(appConfig.app)
      ];
    }
  }
}

However, if my URL has a '.' (period) in it, Grunt fails to reload the page. I am using HTML5 Mode in my Angular app and that works fine.

Could I please know what part of

[
  require("connect-modrewrite")(["!(\\..+)$ / [L]"])
].concat(
  optBase.map(function (path) { return connect.static(path); })
)

is causing it to fail and how do I fix this?

Note: It fails only on page reload. The first time I visit the route it works, then if I hit refresh it fails.

来源:https://stackoverflow.com/questions/47493760/grunt-url-rewrite-in-angular-application-on-page-reload

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!