-
Notifications
You must be signed in to change notification settings - Fork 595
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
supporting anchor links #65
Comments
agreed - think this is related to yoshuawuyts/sheet-router#15; we should def think of a way to resolve this |
We should probs do a |
Actually yoshuawuyts/sheet-router#15 (comment) might have a better solution. Hmmm, I might need some breathing room from |
Apparently it's possible - but should probs still fix hah - http://regl.party/api |
Yeah I got that api page working with roughly the code from the example I pasted above 😄 . I'm starting to wonder if this is a bug that needs to be fixed or if this is reasonable default behavior and we should have a good guide for showing how to override the Working on adventuretron today I encountered a similar but different problem, where electron puts Did this to override it: app.model({
namespace: 'location',
state: {
pathname: '/'
},
reducers: {
pathname: function (data, state) {
return { pathname: data.pathname }
}
},
subscriptions: [
function catchLinks (send, done) {
window.onclick = function (e) {
var node = (function traverse (node) {
if (!node) return
if (node.localName !== 'a') return traverse(node.parentNode)
if (node.href === undefined) return traverse(node.parentNode)
if (window.location.host !== node.host) return traverse(node.parentNode)
return node
})(e.target)
if (!node) return
e.preventDefault()
var href = node.href.replace('file://', '')
send('location:pathname', { pathname: href.replace(/#$/, '') }, done)
}
}
]
}) I'm thinking a separate package could be created from that traverse function (which i stole from sheetify 😸) plus maybe a little more logic, and in the choo guide we might say something like: "hey, need to override the location model? you can use whatever-link-catching-module like this, and here's examples for overrides for electron & supporting anchor links using a subscription" That subscription could then look a little simpler: var catchLinks = require('whatever-link-catching-module')
subscriptions: [
function (send, done) {
catchLinks(function (node, location) {
var href = node.href.replace('file://', '')
send('location:pathname', { pathname: href.replace(/#$/, '') }, done)
})
}
] Turns out there are modules that do mostly the right thing with catching links already, like: https://www.npmjs.com/catch-links |
FWIW, this is a current need in my work. I'm getting around the limitation with I'll try to find where the change belongs next I can. I gather this cuts across packages, and perhaps a few other checkboxes for 4.0.0. |
So did we decide to fix this as a bug or instead decide this is a browser feature and documentation is needed to explain how to work around it? |
Just had a discussion about this with @juliangruber, and we came up with the Inline anchor tags and hash routing cannot co-exist in the same application. Hash routes should be explicit in the application. They're enumerable, and // enumerable
app.router('/404', [
[ '/foo', () => {} ],
[ '/foo#bar', () => {} ],
[ '/foo#baz', () => {} ],
])
// '/foo#baz' => OK
// '/foo#ohno' => ERROR // dynamic
app.router('/404', [
[ '/foo', () => {} ],
[ '/foo#:baz', () => {} ],
])
// '/foo#baz' => OK
// '/foo#ohno' => OK An option should be available to enable anchor tag routing, through: Browser routing updates can be disabled as a whole through the existing option Thoughts? - should this proposal perhaps be a separate issue? |
Had a think. No applications mixing anchor links and hash routing in a crucial way come to mind. At the same time, IMHO, I've seen plenty of applications using hash routing that should use path routing instead, and then "enable" anchor links again. Conceptually, I don't see why an application couldn't dynamically differentiate hash-bearing history states with routing implications and hash-bearing history states with anchor links. But practically, that sounds like a nightmare. Not likely worth the effort ... or whatever weight it might add to the bundles. |
I honestly feel like it should use default browser behavior when using an On Tue, Aug 2, 2016 at 5:04 PM, Kyle Mitchell notifications@github.com
Matt McFarland Software Engineer | @docodemore https://twitter.com/docodemore | LinkedIn |
@MattMcFarland Hmm, yeah that does make sense - seems in line with the rest of
@kemitchell Yeah, exactly - this is what I initially thought, but yeah I don't feel like the benefits outweigh the costs |
Using the default sheet-router/href module results in not being able to jump to anchor links when clicked or when first loading a page with a hash that's meant to point to an anchor somewhere on the page.
Supporting anchor links might not be something we want to have in choo by default, but it would be nice to have docs for it somewhere.
This is also potentially a topic for sheet-router.
Here's where I'm at currently with a solution that overrides the default
href
behavior:The text was updated successfully, but these errors were encountered: