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

Bypass link clicks #15

Open
jamesplease opened this issue Apr 28, 2016 · 8 comments
Open

Bypass link clicks #15

jamesplease opened this issue Apr 28, 2016 · 8 comments

Comments

@jamesplease
Copy link
Contributor

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
Copy link
Owner

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
Copy link
Contributor Author

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
Copy link
Owner

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

@dcorb
Copy link

dcorb commented Jun 30, 2016

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
Copy link
Owner

@dcorb I quite like that hey

@jamesplease
Copy link
Contributor Author

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?

@yoshuawuyts
Copy link
Owner

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.

@jamesplease
Copy link
Contributor Author

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 👌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants