问题描述
我已经在我的Firebase托管上部署了reactjs Web应用程序.我将sitemap.xml文件添加到公用文件夹.我编辑了firebase.json
将源路由到sitemap.xml:
I have deployed a reactjs web app on my firebase hosting. I added a sitemap.xml file to the public folder. I edited firebase.json
to route the source to sitemap.xml:
"redirects": [
{
"source": "/sitemap",
"destination": "/sitemap.xml",
"type": 302
}
],
"rewrites": [
{
"source": "/*",
"destination": "/index.html"
}
]
但是无论何时我去https://blah blah.com/sitemap
它总是返回index.html
我也试图将其添加到重写中,但是看来它总是返回index.html
.
But when ever I go https://blah blah.com/sitemap
it always returns index.html
I tried to add it to rewrites as well but it seems it always returns index.html
.
我也使用React Router 4
进行路由,也许会影响到这一点.
I am using React Router 4
as well for routing, maybe that effects this.
<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
组件,它可以工作,但是由于重定向,我无法设置Google Search Console站点地图.
How can I add the sitemap to hosting domain? If I add a Redirect
component inside the Switch
it works but then I am unable to set Google search console sitemap because of the redirect.
推荐答案
这对我有用:
"redirects": [
{
"source": "/sitemap",
"destination": "/sitemap.xml",
"type": 301
},
{
"source": "/sitemap/**",
"destination": "/sitemap.xml",
"type": 302
}
]
这篇关于如何在React应用程序的Firebase托管中使用Sitemap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!