0

I have a simple React app hosted in https://alejandromaselli.github.io. Also I've added the React Router module and I've configured a /signin route. But when I access directly like this: https://alejandromaselli.github.io/signin It throws me a 404 error.

I should be noted that when I run it locally I can access the url including the /signin route. (Such as http://localhost:3000/signin)

I will appreciate any support.

  • can you post the content of the "package.json" file please? – Jason Dec 09 '20 at 05:04
  • https://create-react-app.dev/docs/deployment/ https://stackoverflow.com/questions/46056414/getting-404-for-links-with-create-react-app-deployed-to-github-pages https://medium.com/@bennirus/deploying-a-create-react-app-with-routing-to-github-pages-f386b6ce84c2 – chonnychu Dec 09 '20 at 05:05

2 Answers2

0

Try using HashRouter instead of BrowserRouter

https://reactrouter.com/web/api/HashRouter

Relevant link here

sanket naik
  • 118
  • 1
  • 5
0

You need to define the relative path in package.json

Add this in package.json

"homepage": "https://alejandromaselli.github.io/",

Now add basename in BrowserRouter

<BrowserRouter basename="/"/>

This worked for me

For more info visit this link

Building for Relative Paths

You can also use hashRouter, but it will make the url look ugly with a hash(#) on it

fahimchowdhury
  • 196
  • 1
  • 7