Skip to content

Instantly share code, notes, and snippets.

@peterbartha
Last active December 15, 2020 10:57
Show Gist options
  • Save peterbartha/e46f923f01a139c864b982c456dc358e to your computer and use it in GitHub Desktop.
Save peterbartha/e46f923f01a139c864b982c456dc358e to your computer and use it in GitHub Desktop.
Parsing (decoded) fragment params like query string params
/**
* 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