yoshuawuyts / sheet-router

fast, modular client-side router
MIT License
226 stars 18 forks source link

Bypass link clicks #15

Open jamesplease opened 8 years ago

jamesplease commented 8 years ago

Sometimes relative links need to be handled like usual in JS apps, like when logging in. A pattern I've used to get this functionality is to add a data-bypass boolean attr to my links to indicate that it should be bypassed.

Is this something you're interested in adding to sheet-router directly, or nah? nbd either way – just figured I'd ask the Q.

yoshuawuyts commented 8 years ago

Hey there, thanks for opening this issue. Do you have a concrete example? I'm having trouble coming up with cases where this is strictly necessary. Thanks!

jamesplease commented 8 years ago

Sure - Ill elaborate on the user logins I mentioned above. With Passport + OAuth2, the handling is done server-side, so a hard page load needs to be done against a particular URL, such as /login/google.

Here's an example app with Passport + FB login. Although it's not a SPA, the endpoint for logging in works the same even if it were.

yoshuawuyts commented 8 years ago

Ah yeah, this definitely makes sense. I reckon it should probably be part of href.js as it relates to handling links.

dcorb commented 8 years ago

For reference ,In page.js they ignore:

Links that are not of the same origin Links with the download attribute Links with the target attribute Links with the rel="external" attribute http://visionmedia.github.io/page.js/

yoshuawuyts commented 8 years ago

@dcorb I quite like that hey

jamesplease commented 8 years ago

Default behavior is definitely a good idea, too. I included some default behavior in Backbone.Intercept (an analogous thing for the BB world). Other ideas for things to ignore could be:

Perhaps the idea of default behavior should be a separate issue? I still think the ability to opt-out on a per-link basis is separately important. App requirements can be weird, and it's a bummer to have to turn off this entire feature for a single link that doesn't fit the default behavior, ya know?

yoshuawuyts commented 8 years ago

Alright then, so to sum up the stuff we should not trigger an href on:

Adtionally we should also be able to flag links explicitely, for example by setting:

<a href="/foo/bar" data-router="false">
  my cool link
</a>

Or something similar; let me know what you think.

jamesplease commented 8 years ago

Sounds good to me, @yoshuawuyts .

I just read over the README of Intercept to see if I missed anything, and two things came up. The first is intercepting form submissions that don't have an "action" attribute set.

The second is that I provided options to change the behavior of forms and links independently at start up. This could maybe be useful, but less so than everything else mentioned, I think 👌