相关疑难解决方法(0)

React Routing在本地机器上工作,但不在Heroku中工作

在这里反应/反应router/heroku问题(它可能是heroku失败的地方).

我正在关注这个精彩的教程:https://medium.com/@patriciolpezjuri/using-create-react-app-with-react-router-express-js-8fa658bf892d#.y77yjte2j ,一切工作到我发布的地步它到heroku,我尝试导航到https://appname.herokuapp.com/about,我得到404 Not Found/nginx错误.当然,根据教程,它应该显示一个关于页面.

底线:React路由器无法在heroku上工作,我无法弄清楚原因.

我已经尝试修改我的server/app.js文件,如下所示:React路由在facebook的create-react-app构建中不起作用

// server/app.js
const express = require('express');
const morgan = require('morgan');
const path = require('path');

const app = express();

console.log('hi from /src/server.js')
// Setup logger
app.use(morgan(':remote-addr - :remote-user [:date[clf]] ":method :url HTTP/:http-version" :status :res[content-length] :response-time ms'));

// Serve static assets
app.use(express.static(path.resolve(__dirname, '..', 'build')));

// Always return the main index.html, so react-router render the route in the client

app.get('/about', (req, res) => {

  console.log('hi from …
Run Code Online (Sandbox Code Playgroud)

javascript heroku reactjs react-router

27
推荐指数
2
解决办法
2万
查看次数

标签 统计

heroku ×1

javascript ×1

react-router ×1

reactjs ×1