As i understand, web servers like nginx
do not support client-side
routing by default, so i use this script to make it work :
public/404.html
<script type="text/javascript">
var pathSegmentsToKeep = 1;
var l = window.location;
l.replace(
l.protocol +
"//" +
l.hostname +
(l.port ? ":" + l.port : "") +
l.pathname
.split("/")
.slice(0, 1 + pathSegmentsToKeep)
.join("/") +
"/?/" +
l.pathname
.slice(1)
.split("/")
.slice(pathSegmentsToKeep)
.join("/")
.replace(/&/g, "~and~") +
(l.search ? "&" + l.search.slice(1).replace(/&/g, "~and~") : "") +
l.hash
);
</script>
Without this script, only the home page will work and other pages will give 404 not found
, using this script website pages works fine, but recently i’ve used reloadDocument
to force page refresh and scroll bar to go to the very top of page when page is visited, but that causes the 404 not found
problem again, how to fix it ?