AmpersandJS / ampersand-router

Clientside router with fallbacks for browsers that don't support pushState. Mostly lifted from Backbone.js.
MIT License
70 stars 16 forks source link

Incorrect routing of anchors when root is set #26

Open nrbrook opened 9 years ago

nrbrook commented 9 years ago

When a non-empty root is set during router start, routing of clicked anchors fails.

This happens because the anchor pathname is used, which includes the root, which is passed to navigate, which passes that to getFragment, which fails to remove the root from the fragment.

nrbrook commented 9 years ago

Temp fix:

    this.router = new Router();
    var oldGetFragment = this.router.history.getFragment;
    this.router.history.getFragment = function (fragment) {
        if(fragment) {
            var root = this.root.slice(1);
            if (!fragment.indexOf(root)) fragment = fragment.slice(root.length);
        }
        return oldGetFragment.call(this, fragment);
    };
ruiramos commented 9 years ago

Just ran into the same problem, thanks @nrbrook, it would be a valuable fix in ampersand-history!

nikolenkoanton92 commented 8 years ago

I got same bug today, @nrbrook thanks for temp solution