Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/41.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.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路由器,html5模式总是刷新到/_Angularjs_Node.js_Express_Angular Ui Router - Fatal编程技术网

Angularjs 角度ui路由器,html5模式总是刷新到/

Angularjs 角度ui路由器,html5模式总是刷新到/,angularjs,node.js,express,angular-ui-router,Angularjs,Node.js,Express,Angular Ui Router,我试图在angular中使用HTML5模式,这样我就可以为一个页面添加书签,比如http:/myhost/products(其中/products是由$stateProviderRef.state(xxx)定义的路由) 为此,我已经 在我的应用程序配置中添加了$locationProvider.html5Mode(true) 将“base href=“/”(带)添加到my index.html 在node.js中将catch all重写添加到my server.js app.get('*',函

我试图在angular中使用HTML5模式,这样我就可以为一个页面添加书签,比如http:/myhost/products(其中/products是由$stateProviderRef.state(xxx)定义的路由)

为此,我已经

  • 在我的应用程序配置中添加了$locationProvider.html5Mode(true)
  • 将“base href=“/”(带)添加到my index.html
  • 在node.js中将catch all重写添加到my server.js

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

  • 重新启动节点服务器

因此,所发生的是,应用程序启动正常,所有导航工作正常,我可以转到,一切正常

但是,如果此时按“刷新”,我将重定向回索引页。在我看来,ui路由器要么正在丢失路径(/products),要么在配置/设置中遗漏了某些内容

我一直在浏览有关StackOverflow的问题,直到我的眼睛流血为止,但所有类似问题的解决方案都是我已经做过的(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'));
    });
更多信息,请查看此生成器