【发布时间】:2019-03-22 00:21:21
【问题描述】:
理论上这应该可行,在/ 文件夹中添加文件/static.json,这会使所有内容都转到React index.html。
(相关)
React Routing works in local machine but not Heroku
https://github.com/heroku/heroku-buildpack-static#configuration
在我的情况下它不起作用,我得到一个 Cannot GET /hello 而不是接收 index.html。令人惊讶的是,如果我直接转到/index.html,我会得到页面但没有激活任何路由。
发生了什么,我该如何解决?
更新:没有运气
/static.jason/src/static.jason/client/static.jason/client/src/static.jason
/static.json
{
"routes": {
"/**": "index.html"
}
}
/client/src/index.js
import React from 'react';
import ReactDOM from 'react-dom';
import FileUpload from './FileUpload';
ReactDOM.render(
<div><FileUpload /></div>,
document.getElementById('root')
);
/client/src/FileUpload.mjs
import React, { Component } from 'react';
import { BrowserRouter as Router, Route } from 'react-router-dom';
class TextFileReader extends Component {
render() {
return (
<Router>
<div>
<Route path="/heyyo" render={() => <span>heyyo</span>} />
<Route exact path="/" render={() => <div>resting</div>} />
<Route path="/what" render={() => <div>what</div>} />
NO ROUTES HERE
</div>
</Router>
)
}
}
export default TextFileReader;
【问题讨论】:
-
你把你的 static.json 放在哪里了?使用您的客户端或服务器 package.json?
标签: reactjs heroku react-router