在Heroku上配置单个页面Create-React-App [英] Configuring a single page Create-React-App on Heroku

查看:150
本文介绍了在Heroku上配置单个页面Create-React-App的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有了Firebase托管,当您部署应用程序时询问您是否将所有网址重写为/index.html。这意味着反应路由器路由将被正确触发,无论它们是直接访问还是从主页。

With Firebase Hosting, when you deploy an app you are asked whether to rewrite all urls to /index.html. This means react-router routes would be properly fired whether they are accessed directly or navigated to from the homepage.

我们使用创建反应-app 创建-反应-app-buildpack 进行部署到Heroku。我们如何以相同的方式将所有URL重写为/index.html?

We use Create-react-app and Create-react-app-buildpack to deploy to Heroku. How can we rewrite all the URLs to /index.html in the same manner?

此问题,说明有关 routes指令,我在根目录中配置了static.json无用:

Following this issue, explaining about the routes directive, I configured a static.json in the root to no avail:

{
  "routes": {
    "/images/*": "/images/",
    "/legal/*": "/images/",
    "/media/*": "/media/",
    "/fav/*": "/fav/",
    "/styles/*": "/styles/",
    "/**": "index.html"
  }
}


推荐答案

在项目中创建 static.json 文件具有以下内容的root:

Create a static.json file in the project root with the following content:

{
  "root": "build/",
  "routes": {
    "/**": "index.html"
  }
}

摩尔e 此处

这篇关于在Heroku上配置单个页面Create-React-App的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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