Reactjs 反应路由器不';我没见过他和heroku合作制作

Reactjs 反应路由器不';我没见过他和heroku合作制作,reactjs,heroku,react-router,Reactjs,Heroku,React Router,我在heroku上上传了我的应用程序。我想example.herokuapp.com/someRoute与localhost:3000/someRoute一样工作(它在本地工作,但在heroku上上传时不工作)我应该怎么做才能使它工作?我尝试使用此配置添加static.json文件 { "root": "build/", "routes": { "/**": "index.html"

我在heroku上上传了我的应用程序。我想
example.herokuapp.com/someRoute
localhost:3000/someRoute
一样工作(它在本地工作,但在heroku上上传时不工作)我应该怎么做才能使它工作?我尝试使用此配置添加static.json文件

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

但它并没有改变任何东西:(有任何关于如何修复它的建议吗?

在使用提供索引文件时,您可能会遇到一个错误,例如,res.sendFile from/client/public folder。相反,在生产环境中,您应该从/client/build提供它

请在生产中提供构建中的文件,在开发中提供公共中的文件

示例如下:

if (process.env.NODE_ENV === "production") {
  app.use(express.static("client/build"));
  app.get("/*", function(req, res) {
    res.sendFile(path.join(__dirname, "./client/build/index.html"));
  });
}

else {
  app.use(express.static(path.join(__dirname, '/client/public')));
  app.get("/*", function(req, res) {
    res.sendFile(path.join(__dirname, "./client/public/index.html"));
  });
}

在使用提供索引文件时,您可能会遇到一个错误,例如,res.sendFile from/client/public folder。相反,在生产环境中,您应该从/client/build提供索引文件

请在生产中提供构建中的文件,在开发中提供公共中的文件

示例如下:

if (process.env.NODE_ENV === "production") {
  app.use(express.static("client/build"));
  app.get("/*", function(req, res) {
    res.sendFile(path.join(__dirname, "./client/build/index.html"));
  });
}

else {
  app.use(express.static(path.join(__dirname, '/client/public')));
  app.get("/*", function(req, res) {
    res.sendFile(path.join(__dirname, "./client/public/index.html"));
  });
}

我想问题是我根本没有添加res.sendFile…我不知道应该如何添加它,因为我使用的是控制器…这是我的代码``app.use(express.static(path.join(u dirname,'client/build'));app.use(bodyParser.urlcoded({extended:true}));app.use(bodyParser.json());app.use('/',mainController);app.listen({port},=>{console.log(
app位于端口:${port}
);});process.on('uncaughtException',(err,origin)=>{console.log(err);})“``我使用公共文件夹还是构建文件夹有关系吗?是的,有关系。构建文件夹是heroku在生产过程中使用的文件夹,这也是一种标准做法!我的问题是,我根本没有将客户端文件夹上传到github,现在我无法添加它,所以我将不得不做一个新的应用程序。顺便问一下,代码可以这样做吗?如果我想问题是我根本没有添加res.sendFile…我不知道应该如何添加它,因为我使用的是一个控制器…这是我的代码``app.use(express.static(path.join(u dirname,'client/build'));app.use(bodyParser.urlcoded({extended:true}));app.use(bodyParser.json());app.use('/',mainController);app.listen({port},()=>{console.log(
app位于端口:${port}
);});process.on('uncaughtException',(err,origin)=>{console.log(err);})“``我使用公共文件夹还是构建文件夹有关系吗?是的,有关系。构建文件夹是heroku在生产过程中使用的文件夹,这也是一种标准做法!我的问题是,我根本没有将客户端文件夹上传到github,现在我无法添加它,所以我将不得不做一个新的应用程序。顺便问一下,代码可以这样做吗?如果你用我刚才提到的方式来做肯定会有用的!