hash-match
hash-match makes it easier to match window.location.hash with a router like wayfarer.
install
npm i --save hash-match
usage
var match = ;;// returns "/weeee" ;// returns "/weeee"
So it's only really interesting if you use it like this:
;// returns whatever the hash is
You can optionally set a prefix:
and if the hash looks like '#/hmm/whatever'
or '#hmm/whatever'
then you'll get '/whatever'
in return.
ok but why
For feeding the output of hash-match into a router like wayfarer.
Here's an example:
var hashMatch = ;var router = default: '/' ; router router // Here's where hashMatch does its thing:router;
Now when you navigate to example.com/#/wat
or example.com/#wat
the /wat
route will execute.
And if you want you can listen for the hashchange
event to update the router:
window;