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.
@edina-a
Copy link

edina-a commented Mar 29, 2017

👍

@MichalCz
Copy link

MichalCz commented Nov 29, 2018

Perhaps you'd consider ditching the semicolon from '://' - protocol agnostic links won't work with your class (like //static.example.com/some/image.png which work well and creating a element is not necessary - at least if there's a // on the first char. :)

@gkiely
Copy link

gkiely commented Feb 19, 2019

V4 uses import {Link as ReactLink} from 'react-router-dom';

@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