当我刷新网站时,我收到 404。这是使用 Angular2、Typescript 和 Firebase 实现的。
我已使用 Angular2 应用程序部署到 firebaseapp。
路线似乎变化得很好,但当我刷新浏览器时,它会将我重定向到 404 页面。
当我在本地刷新时,这种情况不会发生。
我是否缺少任何路线设置或 Firebase 设置?
这是我的 firebase.json 文件:
{
"firebase": "test",
"public": "src",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
}
对于 Firebase 托管,有关重定向和重写的文档位于:https://www.firebase.com/docs/hosting/guide/url-redirects-rewrites.html
从那里:
当您想要为多个 URL 显示相同的内容时,请使用重写。重写对于模式匹配特别有用,因为您可以接受任何与模式匹配的 URL,并让客户端代码决定显示什么。
您可能正在该页面上寻找第一个重写示例:
"rewrites": [ {
"source": "**",
"destination": "/index.html"
} ]
这是 Web 服务器为任何传入请求提供服务的指令,无论路径是什么。
"hosting": {
"rewrites": [ {
"source": "**",
"destination": "/index.html"
} ]
}
)。在这种情况下,您需要在网络服务器上进行一些配置,以便为每个路由对应的每个 URL 加载
HTML5LocationStrategy
(您的入口点文件)。如果想切换到HashBang方式,需要使用这个配置:
index.html
这样的话,当你刷新页面时,就会再次显示。
希望对您有帮助, 蒂埃里
import {bootstrap} from 'angular2/platform/browser';
import {provide} from 'angular2/core';
import {ROUTER_PROVIDERS} from 'angular2/router';
import {LocationStrategy, Location, HashLocationStrategy } from 'angular2/router';
import {MyApp} from './myapp';
bootstrap(MyApp, [
ROUTER_PROVIDERS,
provide(LocationStrategy, {useClass: HashLocationStrategy}
]);
它将切换到 HashLocationStrategy。Angular 文档