reactjs - 如何在带有 React 应用程序的 Firebase 托管中使用站点地图
问题描述
我已经在我的 firebase 主机上部署了一个 reactjs 网络应用程序。我将 sitemap.xml 文件添加到公用文件夹中。我编辑firebase.json
将源路由到 sitemap.xml:
"redirects": [
{
"source": "/sitemap",
"destination": "/sitemap.xml",
"type": 302
}
],
"rewrites": [
{
"source": "/*",
"destination": "/index.html"
}
]
但是当我去的时候https://blah blah.com/sitemap
它总是返回index.html
我试图将它添加到重写中,但它似乎总是返回index.html
。
我React Router 4
也在使用路由,也许这会影响这个。
<Switch>
<Route component={Login} exact path="/login" />
<Route component={Home} path="/home" />
<Route component={About} path="/about" />
<Route component={Carousel} path="/carousel/:galleryRef/:ref" />
<Route component={RelayEditPage} path="/edit/:galleryRef" />
<Route path="/" render={() => <Redirect to="/home" />} />
</Switch>
如何将站点地图添加到托管域?如果我在其中添加一个Redirect
组件,Switch
它可以工作,但是由于重定向,我无法设置 Google 搜索控制台站点地图。
解决方案
这对我有用:
"redirects": [
{
"source": "/sitemap",
"destination": "/sitemap.xml",
"type": 301
},
{
"source": "/sitemap/**",
"destination": "/sitemap.xml",
"type": 302
}
]
推荐阅读
- javascript - Laravel app.js: Uncaught ReferenceError jQuery / $ / moment is not defined - 如何使用这个?
- html - 单击按钮时无法显示图表
- c# - 如何在 Visual Studio 2019 中使用设置安装程序为 WPF 核心 3.1 创建设置文件
- javascript - 直接在 Handlebars 模板中添加数组长度的 if 条件
- arrays - 在 Matlab 数组的每一行中索引相同/不同的元素
- c# - ml.net 异常检测无法正常工作
- python - 从网页中抓取会创建一个空数据框
- spring-boot - N1qlPrimaryIndexed 替换
- containers - Azure ML 容器上的 h2o 模型
- laravel - Laravel 管理队列管理器,用于在单个服务器上进行生产和登台