为角2的路由器坏了使用HTML5路由时? [英] Is Angular 2's Router broken when using HTML5 routes?

查看:222
本文介绍了为角2的路由器坏了使用HTML5路由时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个全新的构造结航线响起异想天开,现在我认为它实际上是。我放弃了试图使其工作,在这里我注意到,甚至在角2页主示例工作。如果打开活生生的例子,你试一试只需点击它的作品很酷,你可以看到在URL中的路径得到改变,但它只改变路径不存在真正的字符串,如果复制您的网址并把它发送给别人,他们将收到以下错误:

This whole new routes syntaxis sounded to good to be true and now I'm thinking it actually is. I gave up trying to make it work and here I am noticing that not even the main example in the Angular 2 page works. If you open the live example and you try it just clicking it works cool and you can see the path in the url gets changed, but it is only changing the String the path doesn't really exists, if you copy your url and sending it to someone they will get the following error:

{
    "statusCode": 404,
    "error": "Not Found"
}

地狱即使你只是刷新页面,你会得到同样的错误。

Hell even if you just refresh the page you will get the same error.

如果您想重现该问题打开这个网址:

If you want to reproduce the issue open this URL:

<一个href=\"https://angular.io/resources/live-examples/tutorial/ts/plnkr.html\">https://angular.io/resources/live-examples/tutorial/ts/plnkr.html

点击在现场preVIEW右上角的启动preVIEW在单独的窗口按钮,等待它加载网页,当你看到网址更改为类似:

Click the "Launch the preview in a separate window" button in the top right of the live preview, wait for it to load the page and when you see the URL changing to something like:

<一个href=\"http://run.plnkr.co/KMzM8hkaCyhlnf3b/dashboard\">http://run.plnkr.co/KMzM8hkaCyhlnf3b/dashboard

做一个F5刷新页面,你会得到错误。

do an F5 to refresh the page and you'll get the error.

这是一个bug,它的它应该工作的方式,或者说他们甚至不尝试一下呢?难道他们已经与一个坏路由器实现再次启动或我只是完全失去了我如何努力使工作?请指点!

Is this a bug, its the way its supposed to work, or something they didn't even try? Are they already starting once again with a bad router implementation or I'm just totally lost on how I'm trying to make it work? Please advice !

我猜我最好使用这个标签的实现。

I'm guessing I'm better off using the hashtag implementation.

推荐答案

在事实上,这是正常现象,请上传您的应用程序时,因为浏览器内的实际地址更新(无需#/ hashbang方法)有一个404错误。默认情况下,HTML5历史用于Angular2重用。

In fact, it's normal that you have a 404 error when uploading your application since the actual address within the browser is updating (and without # / hashbang approach). By default, HTML5 history is used for reusing in Angular2.

如果你想没有一个404错误,你需要更新你的服务器以服务于index.html文件为每个路由路径。

If you want not having a 404 error, you need to update your server to serve the index.html file for each route path.

这个链接可以帮助你还有:<一href=\"http://stackoverflow.com/questions/34415725/when-i-refresh-my-website-i-get-a-404-this-is-with-angular2-and-firebase/\">When我刷新我的网站,我收到了404这是Angular2和火力。

This link could help you as well: When I refresh my website I get a 404. This is with Angular2 and firebase.

希望它可以帮助你,
蒂埃里

Hope it helps you, Thierry

这篇关于为角2的路由器坏了使用HTML5路由时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆