当我刷新我的网站时,我得到一个 404.这是 Angular2 和 firebase [英] When I refresh my website I get a 404. This is with Angular2 and firebase
问题描述
当我刷新网站时出现 404.这是使用 Angular2、typescript 和 firebase.
我已经使用我的 Angular2 应用部署到 firebaseapp.
I've deployed to firebaseapp with my Angular2 app.
路由似乎改变得很好,但是当我刷新浏览器时,它会将我重定向到 404 页面.
Routes seem to change fine but when I refresh the browser it redirects me to 404 page.
当我在本地刷新时,这不会发生.
When I refresh locally this doesn't happen.
我是否缺少任何路由设置或 Firebase 设置?
Am I missing any route settings or Firebase settings?
这是我的 firebase.json 文件:
{
"firebase": "test",
"public": "src",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
}
推荐答案
对于 Firebase 托管,有关重定向和重写的文档在这里:https://www.firebase.com/docs/hosting/guide/url-redirects-rewrites.html
For Firebase Hosting the documentation on redirects and rewrites is here: https://www.firebase.com/docs/hosting/guide/url-redirects-rewrites.html
从那里:
如果您想为多个 URL 显示相同的内容,请使用重写.重写对于模式匹配特别有用,因为您可以接受与模式匹配的任何 URL,并让客户端代码决定要显示的内容.
Use a rewrite when you want to show the same content for multiple URLs. Rewrites are particularly useful with pattern matching, as you can accept any URL that matches the pattern and let the client-side code decide what to display.
您可能正在寻找该页面上的第一个重写示例:
You're likely looking for the first rewrite sample on that page:
"rewrites": [ {
"source": "**",
"destination": "/index.html"
} ]
这是 Web 服务器为任何传入请求提供 /index.html
服务的指令,无论路径是什么.
This is an instruction for the web server to serve /index.html
for any incoming request, no matter what the path is.
这篇关于当我刷新我的网站时,我得到一个 404.这是 Angular2 和 firebase的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!