Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save shprink/bf9599e1d66b9dc4d151e89c1199ccb8 to your computer and use it in GitHub Desktop.
Save shprink/bf9599e1d66b9dc4d151e89c1199ccb8 to your computer and use it in GitHub Desktop.
@colinschoen
Copy link

Here is an alternative utility function:

const isInternalURL = (to: string) => {
  try {
    const url = new URL(to, window.location.origin);
    return url.hostname === window.location.hostname;
  } catch {
    return false;
  }
};

@evadecker
Copy link

evadecker commented Apr 14, 2020

Here is an alternative utility function:

const isInternalURL = (to: string) => {
  try {
    const url = new URL(to, window.location.origin);
    return url.hostname === window.location.hostname;
  } catch {
    return false;
  }
};

This is awesome, thank you @colinschoen!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment