-
Notifications
You must be signed in to change notification settings - Fork 414
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
don't route on same url #39
Conversation
I feel this would be a bad idea. One of the most annoying things with js sites is when I click something that I think is a link or button and absolutely nothing happens. Also supporting the core standards wherever possible is just a good habit. It would be nice if this functionality could be added to a 'beforeRoute' filter or some such. Then it could be optional and you could add some animation that tells the use they are already on that page. This is all just IMHO though... |
I wrote this code because i had an anchor like this: <a href="" class="btn btn-primary foo">Button</a> When user clicks this button, page is being re-rendered. I was doing something else when user clicks this button, it seemed annoying. Maybe if i replace code like this it would be better ? if(el.href == "")
return; I think if href is empty it shouldn't be considered as a link. |
@yasinuslu, that looks like Bootstrap 3. If so this is what I do: <a class="btn btn-primary foo">Button</a> No If your not using bs3 or if this doesn't work for you then you call always do this: EDIT: sorry for the CoffeeScript, here is the js version Template.[name].events({
'click .foo': function (e) {
e.preventDefault()
}
}); |
I tried every method i know for stopping other handlers. 'click .foo': function (e, temp) {
e.preventDefault();
e.stopImmediatePropagation();
e.stopPropagation();
// do something
return false;
} I even returned false just in case :) I'm deliberately making publication wait to observe, By the way i'm using bootstrap 2 for this project. |
It's possible that the router is intercepting the event before your click handler is called. Let me take a look at that code (I wrote it a while ago). We might be able to put the event handling code in deferred block to give your event handlers a chance to be attached first. EDIT: @CMToups is right in comment below. The onClick handler is not honoring if the event was previously stopped. I'll fix that. |
Apologies, its seems I pulled all the |
Thanks @cmather that would be awesome :) I opened this as a PR just because it's easier to show in code. I couldn't made my point in an issue. I knew it wasn't a good solution :) |
@CMToups, Yeah that's probably a better solution actually. EDIT: Oops I see two posts now. @yasinuslu, Cool :-). No worries. Glad we got to the bottom of it. |
Yeah @cmather i missed @CMToups 's post, he was really fast :) |
Fixed on dev. I will do another release once we've amassed enough changes. If you'd like to work off of the dev branch I recommend the following workflow:
export PACKAGE_DIRS="~/code/packages" Work off of whatever branch of the project you want. If you update the package or add the package with a regular |
Router is re-rendering whole page when click on links with empty hrefs. I think router shouldn't re-render for current url.