【发布时间】:2018-11-25 02:15:08
【问题描述】:
我已经在我的 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>
如何将站点地图添加到托管域?如果我在Switch 中添加Redirect 组件,它可以工作,但是由于重定向,我无法设置谷歌搜索控制台站点地图。
【问题讨论】:
-
尝试从
firebase.json中删除对sitemap.xml的任何引用。由于您在那里存在一个静态文件,因此应该根据hosting priorities 返回 -
@abraham 感谢您的回复。我已经删除了所有引用,但是当我执行
domain.com/sitemap.xml时,它总是回退到/并加载主页。 -
如果我在 localhost 上运行它,它如何工作。只有 Firebase 主机总是将我重定向到“/”
-
@abraham 你能提供你的 firebase.json 托管部分的 sn-p 吗?
标签: reactjs firebase sitemap firebase-hosting google-search-api