如何在React应用程序的Firebase托管中使用Sitemap [英] How to use sitemap in firebase hosting with react app

查看:117
本文介绍了如何在React应用程序的Firebase托管中使用Sitemap的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在我的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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆