angular ui-router, html5 模式总是刷新到 /

angular ui-router, html5 mode always refreshes to /

我正在尝试在 angular 中使用 html5mode,这样我就可以为像 http:/myhost/products 这样的页面添加书签(其中 /products 是由 $stateProviderRef.state(xxx ))。

为此我

所以发生的事情是应用程序启动正常,所有导航正常,我可以转到 http://myhost/products 并且一切正常。

但是,如果我此时按刷新,我将被重定向回索引页面。在我看来,好像 ui-router 正在丢失路径(/products)或者我在配置/设置中遗漏了一些东西

我一直在浏览 Whosebug 上的问题,直到我的眼睛流血,但所有类似问题的解决方案都是我已经做过的事情(base=、重定向等)

其他人有这个问题并解决了吗?如果您能分享您的发现,我们将不胜感激。

谢谢

你不应该像那样在服务器中重定向

app.get('*', function(req, res) { res.redirect('/'); });

相反,发送相同的 index.html

app.route('/*')
    .get(function(req, res) {
      res.sendFile(path.resolve(app.get('appPath') + '/index.html'));
    });

查看此生成器了解更多信息

https://github.com/DaftMonk/generator-angular-fullstack/blob/master/app/templates/server/routes.js