DEV Community

Discussion on: Problem with react-router app and Github Pages (Solved !)

Collapse
 
dilinar profile image
Szymon Jergas

I was looking for a solution to this problem.
Unfortunately it does not work and I can't find the problem. I think all the routing in general is correct since it works fine when running locally, but i can't get it to work on gh-pages.
Could You take a look?
github.com/Dilinar/work_management...

Collapse
 
janjibdev profile image
janjibDEV

I guess the problem was solved right. I tried to open your github pages and it works just fine

Collapse
 
dilinar profile image
Szymon Jergas

Oh, I've forgotten to link the deployment.
dilinar.github.io/work_management_...

While it does load the home page properly and going to any subpage via the buttons works, trying to refresh any of the subpages results in a 404 error. Also, going back to the home page loads the error page.

Collapse
 
dilinar profile image
Szymon Jergas

Hi again!
While the information provided here was useful to fix general routing problems, fixing the 404 error on refreshing a sub-page is a different issue.
Gh-pages does not support single page applications, so a workaround is needed. In order to fix the issue, the project requires a custom 404.html file that contains a redirection script.
In other words, instead of allowing gh-pages to open the default 404 error page, we need to have our own that instead of opening, uses a script that takes the previous address and opens it's again.
At least that's how my junior brain understands it. In any case, I've used the steps described here:
github.com/rafgraph/spa-github-pages

Thread Thread
 
jfar41 profile image
ricocode

This is what helped me

ricocode.com

Thread Thread
 
iamashusahoo profile image
Ashutosh

i was not able to understand what it does. tried following the tutorial but not understanding. Is there any tutorial or video?