onNoMatch invoked on every URL hit #160

Open
slisznia opened this Issue Feb 14, 2014 · 4 comments

5 participants

@slisznia

Eventually, everything works (routes and pages are found and displayed), but I noticed the onNoMatch gets always invoked, even for registered routes.

In the argument to the callback (options), route attribute is empty: route [] There are no child objects

@finnsson
Owner

Hi,

thanks for the bug report. Could you construct a JsFiddle or JS Bin that illustrates the bug?

@finnsson finnsson added bug bug / investigate and removed bug labels Feb 23, 2014
@joshuadsilva

I've seen this problem too but I haven't had the chance to pull a JSFiddle together, but if you set a breakpoint on the onFailed function (line 101 in the formatted pager.js minified file) on the demo site, it pretty much hits that breakpoint as you navigate through the entire demo.

image

@nfriend

+1

@pflugs30

I can confirm this is an issue after having tested what @joshuadsilva included above. It seems that the onMatch is fired twice: once for 'start/pager' and once for 'pager' pages, and then the onNoMatch is fired while the 'pager' page is active. Additionally, the onNoMatch is called with an empty route, just as @slisznia points out.

I think what's happening is that it's trying to show a child page it can't find. Here's what I mean. If I'm on the pager documentation page and click on the pager {} page, the onMatch will be triggered within the showChild method. As the pager iterates through the route (initially 'start/config'), it will eventually show the 'config' page. Then, it will get to this line in showPage:

a ? a(j, c, function() {
g.timeStamp === h && j.showPage(c.slice(1), n, c[0])
}
, i) : j.showPage(c.slice(1), n, c[0])

The boldface code will be called if there is no pageGuard (a). Since we are slicing an array of size 1 (it only has 'config'), we will call showPage for an empty route. It appears that doing so will trigger the onNoMatch event.

I don't have a jsFiddle created for this, but hopefully the description above will be helpful. Thanks for a great tool in pager.js!

Update

To work around this bug in my project, I added a check to my onNoMatch handler to check if the route is empty. Similar to this snippet:

    vm.noPageFound = function (options) {
        if (options.route.length === 0) {
             return;
        }

        // logic here...
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment