baseprime / grapnel

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

Having some problems listening to events and stopping propagation #20

Closed xavicolomer closed 9 years ago

xavicolomer commented 9 years ago

Hi there,

I am having some problems with Grapnel.

1 Listen is not working

I tried using this example but I couldn't make it work. https://github.com/EngineeringMode/Grapnel.js#declaring-multiple-routes

The only way I have to listen to url changes is using get: router.get(MY.PATTERN, function(req, event) { //do something });

2 I cannot event.stopPropagation inside get method

In order to restrict the user to only certain URLs I want to listen to any url change, if the url has a previous pattern match, it is correct, otherwise it is wrong. But I cannot find a way to stop the propagation.

router.get(MY.PATTERN, function(req, event) { event.stopPropagation() //not working. });

router.get(*, function(req, event) { alert('wrong url!'); });

Any ideas / suggestions?

Nicolab commented 9 years ago

Hello,

event.stopPropagation() works well for me with the last version (0.5.2):

router.get('test', function(req, ev) {
  ev.stopPropagation();
});

router.get('*', function() {
  alert('wrong');
});

May be your version or your pattern (MY.PATTERN).

Attention in your example router.get(*, ... the wilcard must be a string router.get('*', ...