sheet-router icon indicating copy to clipboard operation
sheet-router copied to clipboard

Bypass link clicks

Open jamesplease opened this issue 8 years ago • 8 comments

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.

jamesplease avatar Apr 28 '16 05:04 jamesplease

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!

yoshuawuyts avatar Apr 29 '16 02:04 yoshuawuyts

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.

jamesplease avatar Apr 29 '16 03:04 jamesplease

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

yoshuawuyts avatar May 19 '16 13:05 yoshuawuyts

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/

dcorb avatar Jun 30 '16 21:06 dcorb

@dcorb I quite like that hey

yoshuawuyts avatar Jun 30 '16 21:06 yoshuawuyts

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:

  • mailto protocol
  • js protocol
  • page fragments (for apps using pushstate)

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?

jamesplease avatar Jun 30 '16 22:06 jamesplease

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

  • Links that are not of the same origin
  • Links with the download attribute
  • Links with the target attribute
  • Links with the rel="external" attribute
  • Hash links on the same page (document.querySelector("[href='href_value']"))
  • Mailto protocol
  • Js protocol
  • Page fragments (for apps using pushstate)

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.

yoshuawuyts avatar Jul 10 '16 13:07 yoshuawuyts

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 👌

jamesplease avatar Jul 10 '16 17:07 jamesplease