1

I've been trying to suppress the normal routing behavior in a Sammy.js router, but so far I've been unsuccessful.

This other SO answer isn't helpful for two reasons:

  1. The upvoted answer is "unacceptable" in my situation, as one of the "soft" requirements is that any route can be silenced without any knowledge that it could be.
    In other words, a route should be defined normally, and the internals of Sammy should check an option about whether to trigger a route handler or not.

  2. The second answer -

    var new_location = '#foo';
    app.trigger('redirect', {to: new_location});
    app.last_location = ['get', new_location];
    app.setLocation(new_location);
    

    - doesn't work.

As a simple example, a parent object has this method defined:

"navigate": function( href, options ){
    var sammyAppRouter = window.router;

    if( !options ){
        options = {};
    }

    if( options.silent ){
        sammyAppRouter.trigger( "redirect", { "to": href } );
        sammyAppRouter.last_location = [ "get", href ];
    }

    sammyAppRouter.setLocation( href );
}

(where window.router is the global Sammy router)

At the very simplest, my goal is to only change the url and have the url listener ignore that change. It should be possible on a route that would otherwise be matched, so navigate( '/my-route' ) triggers a handler, but navigate( '/my-route', { "silent": true } ); changes the url and does not trigger a handler.

Is it possible to suppress Sammy handlers on a call-by-call basis?

Community
  • 1
  • 1
rockerest
  • 10,412
  • 3
  • 37
  • 67
  • @dave4351 I don't think so... but I can't remember, even ~4 months back! I think I may have resolved my issues by letting the regular router take over and testing for changes. In my case, I was appending ":[some sub-page slug]" (including the colon) to the end of the URL. I wanted the internals of the page to change, but the router didn't need to care. I wound up checking for an unchanged route but a changed "microSlug" and handling that separately from the main route. Not ideal, but it got me past the issue. I can post code if you're interested. I don't think it answers the question, though. – rockerest Jul 29 '15 at 05:51

0 Answers0