Skip to content

React app hosted as Github Project Page. How to display custom 404 page? #11938

Answered by trumanjchan
trumanjchan asked this question in Q&A
Discussion options

You must be logged in to vote

I solved this problem by first doing the Basic Instructions in this guide to fix my endpoints giving the default github 404 page upon refreshing of pages that weren't the root page: https://github.com/rafgraph/spa-github-pages#usage-instructions . I placed the <script></script> inside my 404.html file and put it inside the public folder. Then I added the redirect script into the head of the index.html file.

To display my custom 404 page (PageNotFound.js) I imported Navigate from react-router-dom, and inputted these two routes to App.js:

<Route path='/404' element={<PageNotFound/>} />
<Route path='*' element={<Navigate replace to='/404'/>} />

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@ErikPlachta
Comment options

@prashanth00
Comment options

@AleksandraBakhcheva
Comment options

Answer selected by trumanjchan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants