0

I'm trying to deploy my react app, it works fine with the / page but the routes are a hell...

React code :

import { BrowserRouter, Route, Routes, HashRouter } from "react-router-dom";
export default function App() {
  return (
    <div>
      <HashRouter basename="/">
          <Routes>
            <Route path="/" element={<h1>FJSDHNAOUSHSDOASHJNDAOIS</h1>} />
            <Route
              path="/perro"
              element={
                <img src="https://www.laguiadelvaron.com/wp-content/uploads/2018/03/facebook-omnitrix7-1520172526.jpg"></img>
              }
            />
          </Routes>
      </HashRouter>
    </div>
  );
}

I installed gh-page so I had this package.json :

  "homepage": "https://bonafo.github.io/",
  "scripts": {
    "start": "react-scripts start",
    "predeploy" :"npm run build",
    "deploy" : "gh-pages -d build",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },

I don't know where the error... but the only thing I get when I test the /perro is the 404 from GitHub... I also tried with BrowserRouter, but the same result...

Github repo : https://github.com/BONAFO/bonafo.github.io

Thanks.

nepko
  • 21
  • 4
  • 1
    What is the github project directory? Is this a GitHub user page? Typically the `homepage` parameter would include the project directory, e.g. `"https://bonafo.github.io/myAppProject"`. This might be helpful: https://stackoverflow.com/a/71985764/8690857. – Drew Reese Apr 05 '23 at 15:46
  • First I tried this with this repo `https://github.com/BONAFO/bonafo.github.io`, and in the package I tried `https://bonafo.github.io/` and `https://bonafo.github.io/bonafo.github.io` and now with this `https://github.com/BONAFO/cosai` (with the same code) only changing `/ => /cosai` and package `https://bonafo.github.io/cosai` , same error, main page works fine but when i try https://bonafo.github.io/cosai/perro (i changed `/perro => /cosai/perro`) the same error. But thanks for the advice, I'll put the repo. – nepko Apr 05 '23 at 16:10
  • 1
    Actually, your app seems to be running: https://bonafo.github.io/#/perro Interesting dog picture. Is that a wristwatch for the puppy? – Drew Reese Apr 05 '23 at 16:24
  • What?! Thanks but I don't know why `https://bonafo.github.io/#/perro` but not `https://bonafo.github.io/perro` but... Thanks for the help. – nepko Apr 05 '23 at 16:29
  • 1
    You are using a `HashRouter`, so the app is running from a specific location, e.g. `"https://bonafo.github.io/#/"` and all the app's routes run from `"/"`, e.g. `"/"` and `"/perro"`. – Drew Reese Apr 05 '23 at 16:31
  • 1
    Since it seems your code/app is working I'm voting to close as "Not reproducible or was caused by a typo". Cheers and good luck! – Drew Reese Apr 05 '23 at 16:33

0 Answers0