question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

I’m trying to use a third party library with choo. I’ve actually done it before with choo v3, and now I’m passing it to choo v6. Now this library defines image links like this:

<a href="/link/to/image.jpg">
  <img src="/link/to/image.jpg"/>
</a>

So, my problem is that choo try to handle the image route and throws route not found. Now, in choo docs it says that links are ignored when:

  • the click event had .preventDefault() called on it
  • the link has a target=“_blank” attribute with rel=“noopener noreferrer”
  • a modifier key is enabled (e.g. ctrl, alt, shift or meta)
  • the link’s href starts with protocol handler such as mailto: or dat:
  • the link points to a different host
  • the link has a download attribute

So, my question is is there an easier way to ignore links? without having to use preventDefault and programatic navigation? I remember that before there was a noroute data attribute or similar (maybe in sheet-router times?) is there still something like that?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
tornqvistcommented, Aug 17, 2017

Glad to hear. If you don’t want to fiddle with the source of nanohref, you could just extend choo with this functionality.

var Choo = require('choo')
var nanohref = require('nanohref')

function MyApp(opts) {
  Choo.call(this, Object.assign({}, opts, { href: false }))
}

MyApp.prototype = Object.create(Choo.prototype)

MyApp.prototype.start = function () {
  Choo.prototype.start.call(this)

  var self = this
  nanohref(function (anchor) {
    var href = anchor.href
    var currHref = window.location.href
    if (href === currHref || anchor.dataset.noroute) return
    self.emitter.emit(self._events.PUSHSTATE, href)
  })
}
1reaction
yoshuawuytscommented, Aug 15, 2017

Oh right, i see what you’re doing. What you’re doing is a bit of an edge case, as you’re linking to a route on the same host that the router is not supposed to handle.

Ideally in cases like these the image would be served from a different host, which allows it to continue as intended.

Perhaps you could instead define a view that all it does is render the image? Or perhaps a view that all it does is redirect to the requested resource?

Not sure if any of these cut it tho; maybe you’re right and we should indeed allow for a custom way to flag a link that it shouldn’t be handled. But could you perhaps give any of the above a shot before we get into how these could be handled? Thanks!

On Tue, Aug 15, 2017, 11:11 Brecht Savelkoul notifications@github.com wrote:

If I remember correctly, in earlier versions you had to use event.preventDefault() as well as event.stopPropagation() to stop choo from handling links. Can’t confirm if that’s still the case now, but could be worth trying.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/choojs/choo/issues/546#issuecomment-322419325, or mute the thread https://github.com/notifications/unsubscribe-auth/ACWlei9IMuxt8gUJM0_yAr7oQekCJijSks5sYWCqgaJpZM4O2Xz7 .

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Disable Links | CSS-Tricks
There is a problem though: there is no real way to disable an <a> link (with a valid href attribute) in HTML. Not...
Read more >
Accessibility Skip links - W3Schools
The most common skip link is the first interactive element on a page. It takes the user to the main content, past the...
Read more >
Disavow links to your site - Search Console Help
If you can't remove those links yourself, or get them removed, then you should disavow the URLs of the questionable pages or domains...
Read more >
Disable links.
Hold Ctrl+Alt to disable the links temporarily. This extension is deprecated - Chrome has a built-in feature for this, just holding Alt ...
Read more >
Skip Navigation Links - WebAIM
Visible skip links ... The easiest method of creating a skip navigation link is to put it at or near the top of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found