In theory this should work, adding at the /
folder the file /static.json
that makes everything go to the React index.html
.
(related)
React Routing works in local machine but not Heroku
https://github.com/heroku/heroku-buildpack-static#configuration
In my case it doesn't work, I get a Cannot GET /hello
instead of receiving the index.html. Surprisingly, if I go directly to /index.html
I get the page but no route is activated.
What is happening and how can I fix it?
UPDATE: tried without luck
/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;