0

when I deploy my app on gh-pages, I keep getting a 404 error when I refresh the page on my routes. The only time it doesn't error out is when refreshing on the root ('/') route. Any advice on solving this issue?

Here's the relevant code below and link to my repo and deployed app:

REPO: https://github.com/envincebal/react-game-search
DEMO https://envincebal.github.io/react-game-search/

class App extends Component {
  render() {
    return (
      <BrowserRouter basename={process.env.PUBLIC_URL}>
        <div className="App">
          <Nav />
          <div className="container">
            <Switch>
              <Route exact path="/" component={MainPage} />
              <Route exact path="/games" component={GameSearch} />
              <Route exact path="/about" component={About} />}
              <Route exact path="/details" component={GamesDetails} />}
            </Switch>
          </div>
        </div>
      </BrowserRouter>
    );
  }
} 
const Nav = () => {
  return (
    <div className="navbar">
      <div className="navbar-item">
        <NavLink
          exact to="/"
          activeClassName="selected"
          className="nav-link"
        >Home</NavLink>
      </div>
      <div className="navbar-item">
        <NavLink
          exact to="/games"
          activeClassName="selected"
          className="nav-link"
        >Games</NavLink>
      </div>
      <div className="navbar-item">
        <NavLink
          exact to="/about"
          activeClassName="selected"
          className="nav-link"
        >About</NavLink>
      </div>
    </div>
  );
}
envincebal
  • 153
  • 1
  • 9
  • [You need to teach your server to handle 404s by redirecting to the index.html page](https://stackoverflow.com/a/62050700/2873538). Check these for [github pages](https://github.com/rafrex/spa-github-pages#usage-instructions). See this [SO post](https://stackoverflow.com/q/46056414/2873538) – Ajeet Shah May 31 '20 at 21:20

0 Answers0