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:
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.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?