Skip to content

Instantly share code, notes, and snippets.

@burdiuz
Created December 12, 2018 08:58
Show Gist options
  • Save burdiuz/7417c8adac9700c95bc959c8d5007012 to your computer and use it in GitHub Desktop.
Save burdiuz/7417c8adac9700c95bc959c8d5007012 to your computer and use it in GitHub Desktop.
Getting redirect URL
const getUrlDomainPart = (url) => {
const [part] = url.match(/^https?:\/\/[^\/]+\//) || [];
return part;
};
export const getCurrentUrl = () => {
const url = window.location.href;
const part = getUrlDomainPart(url);
return part ? url.substr(part.length - 1) : '';
};
export const isAcceptableUrl = (url) => {
if (url.charAt() === '/') {
return true;
}
const part = getUrlDomainPart(url);
return Boolean(part && window.location.href.indexOf(part) === 0);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment