Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs UI路由器Backbutton导致重新请求index.html中的所有资产,但前缀为route HTML5模式_Angularjs_Node.js_Html_Express_Angular Ui Router - Fatal编程技术网

Angularjs UI路由器Backbutton导致重新请求index.html中的所有资产,但前缀为route HTML5模式

Angularjs UI路由器Backbutton导致重新请求index.html中的所有资产,但前缀为route HTML5模式,angularjs,node.js,html,express,angular-ui-router,Angularjs,Node.js,Html,Express,Angular Ui Router,我正在使用Angular与UI路由器和Express 我已经设置了$locationProvider.html5Mode(true) 并且在我的index.html文件的中有 在我的服务器上,我有一个catchall路由,如果请求与我现有的api或资产路由之一不匹配,它将发送index.html app.route('/*') .get(function(req, res) { console.log('the req.url', req.url); consol

我正在使用Angular与UI路由器和Express

我已经设置了
$locationProvider.html5Mode(true)

并且在我的
index.html
文件的
中有

在我的服务器上,我有一个catchall路由,如果请求与我现有的api或资产路由之一不匹配,它将发送
index.html

app.route('/*')
    .get(function(req, res) {
      console.log('the req.url', req.url);
      console.log('sending index.html', path.resolve(app.get('appPath') + '/index.html'));
      res.sendFile(path.resolve(app.get('appPath') + '/index.html'));
    });
在90%的情况下,这非常有效。用户可以使用
$state在状态间导航。转到
并使用浏览器刷新按钮刷新这些状态

但是,,如果我导航到
stateA
,然后导航到
stateB
,然后导航到
stateC
,然后点击
browser back按钮
,应用程序会成功切换回
stateB
,然后对
index.html
中的所有资产发出ajax请求,但前缀是
stateB
的路由,结果是:导致应用程序崩溃的大量错误

这些错误是由于我的服务器通过一次又一次地发送
index.html
来响应这些请求,而请求是针对
.js
文件的。。。这是服务器日志

请注意,在我发送
index.html
后,前端如何请求
index.html
中的所有资产,但以路由为前缀,因此我收到的是
bower\u车载组件/*
的请求,而不是
bower\u组件/*
。请注意,当指向
/board intro
刷新浏览器时,不会发生这种情况。我只需收到一个请求并发送
index.html
,它就可以工作了


我已经做了很多小时的研究,找不到另一个与这种情况相匹配的问题。非常感谢您的帮助

所以,经过更多的挖掘,我解决了这个问题

发生的事情是,我在我的项目中加入了
jquerymobile
,以处理触摸事件
jQuery mobile
还处理
客户端路由
,并且与
UI路由器
冲突。我在这里找到了一篇关于如何禁用jQuery mobile的路由的文章

作者正在为
主干
实现此解决方案,但它也适用于
角度
。你所需要做的就是跑步

$(document).bind("mobileinit", function () {

   $.mobile.ajaxEnabled = false;

   $.mobile.linkBindingEnabled = false;

   $.mobile.hashListeningEnabled = false;

   $.mobile.pushStateEnabled = false;

});
之前
jQuery mobile
包含在您的angular项目中。这将关闭
jquerymobile
客户端路由,并允许
UI路由器
完成它的工作