【发布时间】:2017-03-01 17:27:51
【问题描述】:
我的 Angular 2 应用程序使用默认的 HTML 5 history.pushState location strategy。如何使用 history.pushState 配置服务器,以便浏览器刷新和浏览器 URL 不会生成 404s?
例如,Tour of Heroes 应用程序有几个不同的应用程序路由,例如:
http://localhost:8080/dashboard
http://localhost:8080/heroes
http://localhost:8080/detail/13
如果您在其中一个路由上点击刷新,或键入其中一个 URL,您将获得 404,因为 /detail/13 是应用程序路由,而不是服务器资源。我在index.html 的head 顶部配置了定位策略:
<!doctype html>
<html>
<head>
<base href="/">
<meta charset="utf-8">
<title>Tour of Heroes</title>
但是应该如何配置服务器以便将所有 URL 发送到我的应用程序而不是生成 404?
注意: 这个问题是对Angular 2 : 404 error occur when i refresh through Browser 和Angular 2.0 router not working on reloading the browser 询问如何 来解决这个问题的问题的补充。对于 Firebase,有这个:When I refresh my website I get a 404. This is with Angular2 and firebase,对于 Apache,有这个:htaccess redirect for Angular routes。
【问题讨论】:
标签: angular angular2-routing angular2-cli