baseprime / grapnel

The smallest JavaScript router with named parameters, HTML5 pushState, and middleware support
http://grapnel.js.org
467 stars 40 forks source link

Feature Request : options.root applicable for hashbang urls too #38

Closed chandu closed 5 years ago

chandu commented 9 years ago

Thanks for the simple/awesome router.

I looked at the documentation/code and realized that the options.root is only applicable for the pushState mode.

Can this be made applicable to the regular non pushState mode too?

I am aware that router.context(), can help me here, router.context returns only a wrapper to router.get.

I think that the frag.get/set methods needs to be changed to use the options.root for the non pushState mode, but am not good with the pushState/JS tests and don't want to waste your time sending a pull request without test coverage :(

nmsobri commented 7 years ago

On line 244 replace with following code:

if (root.location.hash) {
    frag = root.location.hash.split((self.options.hashBang ? '#!' : '#'))[1]
}
else {
    root.location.hash = (self.options.root) ? self.options.root : '#/';
    frag = root.location.hash.split((self.options.hashBang ? '#!' : '#'))[1]
}