sheet-router
sheet-router copied to clipboard
Bypass link clicks
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.
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!
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.
Ah yeah, this definitely makes sense. I reckon it should probably be part of href.js
as it relates to handling links.
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 I quite like that hey
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?
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.
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 👌