角UI路由器,HTML5模式始终刷新到/

编程入门 行业动态 更新时间:2024-10-27 01:23:10
本文介绍了角UI路由器,HTML5模式始终刷新到/的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想在角使用html5mode,这样我可以为网页添加书签,如http:/为myhost /产品(其中/产品是$ stateProviderRef.state(XXX)定义的路由)。

I am trying to use html5mode in angular, so that I can bookmark a page like http:/myhost/products (where /products is a route defined by$stateProviderRef.state(xxx) ).

要为此我已经

  • 添加 $ locationProvider.html5Mode(真)的,以我的应用程序配置
  • 加入'基地HREF =/(与在<?>)我的index.html
  • 添加了包罗万象的重写我的server.js在node.js中

  • added $locationProvider.html5Mode(true) to my app config
  • added 'base href="/"' (with the <>) to my index.html
  • added the catch all rewrite to my server.js in node.js

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

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

重新启动了节点服务器

那么,什么情况是,应用程序启动正常,所有导航的作品,我可以去的http://为m​​yhost /产品和一切正常。

so what happens is that the app starts ok, all navigation works, I can go to myhost/products and everything works well.

不过,如果我preSS刷新在这一点上,我重定向到索引页面。在我看来,如果UI路由器或者是失去路径(/产品)或我已经错过了在config /设置的东西。

However, if I press refresh at this point, I am redirected back to the index page. Looks to me as if ui-router is either losing the path (/products) or I have missed something in the config / setup

我已浏览通过计算器,直到我的眼睛都在流血的问题,但所有的解决方案,以类似的问题是,我已经做过的事情(基地=,重定向等)

I have been browsing through the questions on StackOverflow until my eyes are bleeding, but all of the solutions to similar problems are things that I've already done (base=, redirect etc)

任何人有这个问题,并解决它?将非常AP preciated,如果你可以分享你的发现。

Anyone else has this problem and solved it ? Would be much appreciated if you could share your findings.

感谢

推荐答案

您不应该在这样的服务器重定向

You shouldn't redirect in server like that

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

相反,发送相同的index.html

Instead, send same index.html

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

看看这个生成更多

Take a look at this generator for more

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

更多推荐

角UI路由器,HTML5模式始终刷新到/

本文发布于:2023-10-31 17:19:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546757.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路由器   模式   UI

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!