如何在Firebase托管中使用站点地图与反应应用程序



我已经在我的Firebase主机上部署了一个reactjs Web应用程序。我在公用文件夹中添加了站点地图.xml文件。我编辑了firebase.json将源路由到站点地图.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组件,它可以工作,但由于重定向,我无法设置 Google 搜索控制台站点地图。

这对我有用:

"redirects": [
{
"source": "/sitemap",
"destination": "/sitemap.xml",
"type": 301
},
{
"source": "/sitemap/**",
"destination": "/sitemap.xml",
"type": 302
}
] 

尝试删除索引.html文件。 我创建了一个网站,因为我从公用文件夹中删除了索引.html而是在函数文件夹中使用了索引.js。

我和你有同样的问题。使用以下配置使我的公用文件夹(包括站点地图(中的文件在部署后可联机访问:

"rewrites": [
{
"source": "/",
"destination": "/index.html"
},
{
"source": "/sitemap",
"destination": "/sitemap.xml"
}
]

最新更新