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.

Allow conditional 'navigo-data' attribute for the '<a href="">' element

See original GitHub issue

Hello,

Firstly, thank you for the great library! The new version (v8) looks very good so far.

Currently, I am facing an issue where sometimes I want to pass a full url e.g. https://github.com/ to the href='' tag without Navigo’s support. Other times I want to pass a local path e.g. path/somewhere and enable Navigo’s functionality by adding navigo-data attribute.

I am using Navigo in conjuntion with Alpine.js and thought I would be able to do something like this <a href="https://github.com/" navigo-data="!this.isUrl"> where isUrl = true.

Maybe there is a way to do this that I don’t know about, please advise.

P.S. I know I could probably achieve this conditionally, either with navigate() function or conditioning the element (<a href='https://'> vs. <a href='/' navigo-data>), but wondering if this could this be a feature?

Thank you ✌️

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
krasimircommented, Jan 13, 2021

Well, updatePageLinks doesn’t remove the listeners that are already attached to links. So, there is some work required to achieve what you want. It’s on my list already.

0reactions
krasimircommented, Jan 13, 2021

There is a new version 8.5.0 which:

  • supports "false" as value of data-navigo attribute. In this case it skips the link and the link works as a normal one
  • skips links with target="_blank"

Also have in mind that if some link is instrumented, or in other words wired to Navigo logic you can change its data-navigo value to "false" and call router.updatePageLinks(). This will remove the click listener and will make the link work as a normal link.

Let me know if it doesn’t work as expected and I’ll reopen the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

<a>: The Anchor element - HTML: HyperText Markup Language
The HTML element (or anchor element), with its href attribute, creates a hyperlink to web pages, files, email addresses, locations in the ...
Read more >
How to add conditional click attribute to link - Stack Overflow
I am trying to make an anchor tag trigger ...
Read more >
How to Render <a> with Optional href in React | Pluralsight
Let's add conditional rendering to it. Optionally Rendering an Element. If the href attribute for the user ...
Read more >
HTML A Href Attribute: A Quick And Simple Guide »
All Attributes of the anchor Element. Attribute name, Values, Notes. hreflang, Specifies the language of the linked resource. download ...
Read more >
How to change the href value of <a> tag after click on button ...
document.getElementsByTagName() Method: It returns a list of the elements that matches the tag name. DOM allows attribute manipulation.
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