Skip to content
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

Closed
wants to merge 1 commit into from
Closed

don't route on same url #39

wants to merge 1 commit into from

Conversation

yasinuslu
Copy link
Contributor

Router is re-rendering whole page when click on links with empty hrefs. I think router shouldn't re-render for current url.

@Sivli-Embir
Copy link

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

@yasinuslu
Copy link
Contributor Author

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.

@Sivli-Embir
Copy link

@yasinuslu, that looks like Bootstrap 3. If so this is what I do:

<a class="btn btn-primary foo">Button</a>

No href disables the <a> tag but bs3 turns it into a button that is still clickable.

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()
  }
});

@yasinuslu
Copy link
Contributor Author

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, still re-rendering.

By the way i'm using bootstrap 2 for this project.

@cmather
Copy link
Contributor

cmather commented Aug 14, 2013

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.

@Sivli-Embir
Copy link

Apologies, its seems I pulled all the href from my code before I moved from router to iron-router. :/ I can confirm your issue and I feel that the router should obey e.preventDefault() given that it is the expected 'default' behavor.

@yasinuslu
Copy link
Contributor Author

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 :)

@cmather
Copy link
Contributor

cmather commented Aug 14, 2013

@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.

@yasinuslu
Copy link
Contributor Author

Yeah @cmather i missed @CMToups 's post, he was really fast :)

@cmather
Copy link
Contributor

cmather commented Aug 15, 2013

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:

  1. Create a directory for local packages. Mine is ~/code/packages
  2. Clone the repo into the iron-router folder (change from meteor-iron-router)
  3. Add a PACKAGE_DIRS export to your .bashrc file
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 meteor add iron-router Meteor will find it in your packages directory.

@cmather cmather closed this Aug 15, 2013
@yasinuslu yasinuslu deleted the no_rerender branch August 15, 2013 08:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants