This question has been asked multiple times, I have been reading the similar questions and attempting to resolve this issue with no luck so I am posting my code to see if a fresh pair of eyes can help solve my problem.
My app works as expected on Heroku, however when refreshing the page or navigating directly to a route that's not the home page (example myapp.com/whatever). I am getting a 404 not found.
My routing works locally so I know it has to do with my app settings and Heroku. I have a MERN application with create-react-app client and express server backend
Folder Stucture
client/
server/
package.json
static.json
static.json
{
"root": "client/build/",
"clean_urls": false,
"routes": {
"/**": "index.html"
}
}
Router.js
<BrowserRouter basename="/">
<Fragment>
<Switch>
<Route exact path="/" component={Home} />
<Route extact path="/login" component={Login} />
<PrivateRoute path="/dashboard" component={Dashboard} />
</Switch>
</Fragment>
</BrowserRouter>
Server.js
if (process.env.NODE_ENV === 'production') {
app.use(express.static('client/build'))
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, '../client', 'build', 'index.html'));
});
}
Anybody see anything that I am missing?