-1

I've developed a react app that is running fine locally. I'm now trying to deploy it using GitHub Pages.

Despite following this tutorial, I get a blank page, and several 404 errors in the logs.

Here is my index.js:

import React from 'react';
import ReactDOM from 'react-dom/client';
import {HashRouter} from "react-router-dom";
import './index.css';
import App from './App';

ReactDOM.createRoot(document.getElementById('root')).render(
    <React.StrictMode>
        <HashRouter>
            <App />
        </HashRouter>
    </React.StrictMode>
);

And the Route defined in App.js

return (
    <>
        <Navbar/>
        <Routes>
            <Route path='/' element={<CoinsTable coins={coins}/>}/>
            <Route path='/coin' element={<CoinDetails/>}>
                <Route path=':coinId' element={<CoinDetails/>}/>
            </Route>
            <Route path='/option-prices' element={<CoinOptionsTable/>}>
                <Route path=':coinId' element={<CoinOptionsTable spotValue={1500} />}/>
            </Route>
        </Routes>

    </>
);

Here is the homepage property I've added to the project's package.json:

"private": false,
"homepage": "https://myusername.github.io/myusername/myreponame",

I've added this to scripts:

"predeploy": "npm run build",
"deploy": "gh-pages -d build",

Then I run this command to deploy the app:

npm run deploy
matdev
  • 4,115
  • 6
  • 35
  • 56
  • 1
    Does this help answer your question? https://stackoverflow.com/a/71985764/8690857 If not, can you [edit] the post to include the router and routes you are rendering as part of a more complete [mcve]? – Drew Reese Mar 30 '23 at 07:56
  • I found the error, thanks ! The problem was that I had repeated my github username in the homepage url before the app name. Correct value for "homepage" is: https://myusername.github.io/myappname – matdev Mar 30 '23 at 20:21

1 Answers1

0

Removing the repeated github username from the homepage url fixed the problem:

Correct value for "homepage":

"homepage": "https://myusername.github.io/myreponame"
matdev
  • 4,115
  • 6
  • 35
  • 56