Skip to content

why doesn't my 404.html redirect to index.html? #55673

Discussion options

You must be logged in to vote

finally solved the problem from stackoverflow . For vite react application, place the 404.html page at public folder, then add configuration to the vite.configure.js so that the 404.html will be place in dist folder after build. Saving you click the stackoverflow link, here is code:
404.html
`

<title>Page Not Found</title> <script> sessionStorage.redirect = location.href; </script> `, place this code to index.html at header section ` <script> (() => { const redirect = sessionStorage.redirect; delete sessionStorage.redirect; if (redirect && redirect !== location.href) { history.replaceState(null, null, redirect); } })(); </script>`, then at vite.configure.js, add this `export default defin…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by ipraisethelord
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Pages Host a static website, right from your repo Question
1 participant