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

问题描述 投票:1回答:3

我在我的firebase托管上部署了reactjs web应用程序。我将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组件它可以工作,但由于重定向我无法设置谷歌搜索控制台站点地图。

reactjs firebase sitemap firebase-hosting google-search-api
3个回答
0
投票

尝试删除index.html文件。我创建了一个网站,我从公共文件夹中删除了index.html,而是在functions文件夹中使用了index.js。


0
投票

我遇到了和你一样的问题。使用以下配置,可以在部署后在线访问公用文件夹(包括站点地图)中的文件:

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

0
投票

这对我有用:

"redirects": [
  {
    "source": "/sitemap",
    "destination": "/sitemap.xml",
    "type": 301
  },
  {
    "source": "/sitemap/**",
    "destination": "/sitemap.xml",
    "type": 302
  }
] 
© www.soinside.com 2019 - 2024. All rights reserved.