0

I am using react router dom with react and deployed on github pages. My problem is that package.json requires settings to build the github link followed by the / and the name of the repo or project.

{
  "name": "self-destructed-messages",
  "homepage": "http://username.github.io/self-destructed-messages/",
  "version": "0.1.0",

I tried with https also and the pages, even the localhost is redirecting me to the error not found page

const RouterConfig = () => {
  return (
    <div>
        <Routes>

                <Route exact path='/' element={<Home />} />
                <Route path='/created-message/:string' element={<CreatedMessages />} />
                <Route path='/get-message/:string' element={<GetMessage />} />
                <Route path='*' element={<NotFounded />} />


        </Routes>
    </div>
  )
}

When I open the github pages it goes automatically to the 404 page (NotFounded). If I am using the / only, I get the github official 404...

I dont know what else to try. Can please have some help? Thanks, Daniel

daniel sas
  • 257
  • 2
  • 9
  • What router are you using? Does this help answer your question? https://stackoverflow.com/a/71985764/8690857 – Drew Reese Jun 03 '22 at 17:46
  • sorry. It doesnt. I use "react-router-dom": "^6.3.0", Github pages still does not recognise the home page. But not, localhost works.. – daniel sas Jun 03 '22 at 17:59
  • Typically if github is intercepting and sending a 404, that means it's not even hitting your React app. If you are getting the `NotFound` element, that means your React Router is not configured the way you are expecting. Inside your NotFound Element, console.log the `location` object and see what React Router is checking. – Alan Jun 03 '22 at 18:45
  • So are you using a `HashRouter` or not? It's rather irrelevant between RRDv5 and v6 as the hash router exists in both and github needs it. You might also need to specify a `basename` prop to the router. In other words, the issue likely isn't with your routes, but the router, and you haven't included all the relevant details/information in your post yet. – Drew Reese Jun 03 '22 at 20:07
  • Yes. I am using hashroute. But i use it in the index.js not in app.js. – daniel sas Jun 04 '22 at 04:10

0 Answers0