Last active
December 15, 2020 10:57
-
-
Save peterbartha/e46f923f01a139c864b982c456dc358e to your computer and use it in GitHub Desktop.
Parsing (decoded) fragment params like query string params
This file contains hidden or 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
/** | |
* If you're working with URL encoded fragments you should probably use URLSearchParams(...) instead of this | |
* solution. Read more: https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams | |
*/ | |
const { hash } = location; | |
const params = new Map(hash.slice(1, hash.length).split('&').filter(elem => elem).map(elem => | |
elem.split('=').map(e => decodeURIComponent(e)) | |
)); | |
// example: | |
// params.get('email'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment