-
Notifications
You must be signed in to change notification settings - Fork 575
Open
Description
Smashing Magazine wanted to solve the same problem as this repository and I think their solution is fairly elegant as well. It involves a small 404 page.
<script>
sessionStorage.redirect = location.href;
</script>
<meta http-equiv="refresh" content="0;URL='/REPO_NAME_HERE'">
Because there's the "refresh" header, this gets translated into a 301 response within the browser (ignoring the 404 status code from the server). To use this, the SPA needs a bit of JavaScript at the very beginning to load the route from session storage and use replaceState
to update the URL.
<script>
(function(){
var redirect = sessionStorage.redirect;
delete sessionStorage.redirect;
if (redirect && redirect != location.href) {
history.replaceState(null, null, redirect);
}
})();
</script>
According to my quick searching, Google doesn't penalize 301 redirects nor the refresh header redirects, so this might be a viable alternative without putting the path after a hash.
- https://www.smashingmagazine.com/2016/08/sghpa-single-page-app-hack-github-pages/ - article
- https://github.com/csuwildcat/sghpa - repo with code and link to GitHub Pages site featuring the redirection
Vince14Genius
Metadata
Metadata
Assignees
Labels
No labels