Socket
Socket
Sign inDemoInstall

auto-redirect

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    auto-redirect

Invisibly apply front-end redirections either by query parameter or by localstorage


Version published
Weekly downloads
5
Maintainers
1
Install size
1.26 kB
Created
Weekly downloads
 

Readme

Source

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>

FAQs

Last updated on 26 Dec 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc