auto-redirect
v0.3.0
Published
Invisibly apply front-end redirections either by query parameter or by localstorage
Downloads
3
Readme
Auto Redirect
Automatically redirect the user to the right path as required by the redirect
query parameter or the localStorage redirect
key:
// https://example.com/?redirect=/abc/def
import "auto-redirect";
console.log(window.location.href);
// https://example.com/abc/def
It is ideal for hosting React websites on Github Pages, where you write this as the 404.html page:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Redirecting...</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<script>
window.location = `/?redirect=${window.location.pathname}`;
</script>
</body>
</html>