我希望从使用AngularJS ngRoute模块切换到ui路由器模块框架。我的应用程序正在使用$locationProvider.html5Mode,为了防止深入链接,我已经安装了connect-modrewrite节点模块(来自https://www.npmjs.org/package/connect-modrewrite),并将其添加到AngularJS Yeoman提供的Grunt文件中,如下所示:
// Yeoman's Gruntfile.js
// placed outside the module.exports function.
var modRewrite = require('connect-modrewrite');
...
// modify the server config and add our modRewrite middleware.
livereload: {
options: {
middleware: function (connect) {
return [
modRewrite([
'!\\.html|\\.js|\\.css|\\.png$ /index.html [L]'
]),
lrSnippet,
mountFolder(connect, '.tmp'),
mountFolder(connect, yeomanConfig.app)
];
}
}
}这很棒,但是现在我切换到使用ui-路由器模块框架,如果我深入链接到(例如) http://myapp.com:9000/products,我会得到响应:
Cannot GET /products显然,当我转到主页/默认页面并单击指向http://myapp.com:9000/products的链接时,一切都很好。有没有人修改他们的grunt文件,以便他们可以使用html5mode和ui路由器与AngularJS约曼生成器?提前谢谢。
发布于 2014-03-30 11:41:35
哇哦!我的错..。我把livereload包含在错误的Grunt任务中!问题解决了..。
发布于 2014-03-30 11:23:52
我从不使用connect-modrewrite,我总是使用nginx。对于我来说,我需要使用apache完成以下工作。
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.html [L]https://stackoverflow.com/questions/22743289
复制相似问题