Created
December 12, 2018 08:58
-
-
Save burdiuz/7417c8adac9700c95bc959c8d5007012 to your computer and use it in GitHub Desktop.
Getting redirect URL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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