0.3.0 • Published 3 years ago

auto-redirect v0.3.0

Weekly downloads
6
License
MIT
Repository
-
Last release
3 years ago

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>