1

I have created an application using React and Ruby on Rails. I deployed my app to Heroku. When running locally, I client-side routing works, but when on the Heroku deployment, I get error 404 when routing directing or refreshing the page. I tried creating a static.json file like this:

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

But no luck. Does anyone have any ideas? I am using React-Router_dom 5.3.3 and my routes look like this right now:

App.js

      return (
    <>
      <Header>
        <NavBar user={user} setUser={setUser} />
      </Header>
      <Content>
        <Switch>
          <Route exact path="/">
            <TicketPage user={user} />
          </Route>
          <Route path="/user">
            <UserPage user={user} />
          </Route>
          <Route path="/mytickets">
            <MyTickets user={user} />
          </Route>
        </Switch>
      </Content>
    </>
  );
}

index.js

import React from "react";
import ReactDOM from "react-dom";
import { BrowserRouter } from "react-router-dom";
import App from "./App";

ReactDOM.render(
  <BrowserRouter>
    <App />
  </BrowserRouter>,
  document.getElementById("root")
);

Thank you!

Brad Bieselin
  • 107
  • 1
  • 11
  • were there any errors in the logs? – jspcal Jul 13 '22 at 19:18
  • No errors, I get this though: This phase-5-capstone.herokuapp.com page can’t be found. No webpage was found for the web address: https://phase-5-capstone.herokuapp.com/user HTTP ERROR 404 – Brad Bieselin Jul 13 '22 at 19:25
  • Maybe this can help you: https://stackoverflow.com/questions/43911928/how-to-render-file-in-rails-5-api/43912670#43912670 – Aymendps Jul 13 '22 at 19:29

0 Answers0