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.

Using data-navigo attribute on a website without a server leads to absolute file path beeing used as location

See original GitHub issue

Hey 😃 I’m really sorry, that the content of this Issue was just ‘Hey 😃’ in a previous version. I accidentally send this request hitting ‘Ctrl + Enter’ and then left for lunch before I was able to finish writing this Issue.

Context:

I want to use Navigo for an offline website, more precise: A documentation for a tool I’m building. The documentation will be shipped in the code for the tool. So when someone needs help with the tool, one only has to open ‘file:///var/users-project/vendor/the-tool/documentation/index.html’ in his browser.

Steps to reproduce:

I created the index.html which contains links of the form:

<a href="overview/getting-started" data-navigo>Getting Started</a>

and defined the router like this:

var router = new Navigo(null, true, '#');
router.on({
    ':article': function (params) {
        var article = params.arcticle;
        //Here I want to replace the content of the body with the content of the file  '{{ article }}.html'
    }
}).resolve();

By doing this, I just have to add new article-html-files and links to them, but don’t have to touch the router configuration when adding an article to the documentation.

When I now open the page in a browser with the link file:///var/the-tool/documentation/index.html and click on the Getting Started link, the URL will be file:///var/the-tool/documentation/index.html#/var/the-tool/documentation/getting-started instead of expected file:///var/the-tool/documentation/index.html#overview/getting-started. Also the article variable gets the value getting-started instead of expected overview/getting-started.

Possible fix

Without having an overview of the inner workings of Navigo. I suggest to change the code from

// ...
Navigo.prototype = {
    //...
    updatePageLinks: function updatePageLinks() {
        // ...
        this._findLinks().forEach(function (link) {
            // ...
            var location = link.pathname;
// ...

to

// ...
Navigo.prototype = {
    //...
    updatePageLinks: function updatePageLinks() {
        // ...
        this._findLinks().forEach(function (link) {
            // ...
            var location = link.getAttribute('href');
// ...

This way the url successfully will be changed to file:///var/the-tool/documentation/index.html#overview/getting-started. But, the article variable still has getting-started instead of expected overview/getting-started as value. I currently don’t know how to fix that.

Am I using Navigo incorrectly or is this a valid bug, that (when fixed) would not break any existing code, that uses Navigo?

Thanks 😃

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
krasimircommented, Apr 25, 2017

4.7.0 released. The router now contains a public methodgetLinkPath. You may overwrite it like so:

router.getLinkPath = function (link) {
  return link.getAttribute('href');
};

Here’s a test case for reference https://github.com/krasimir/navigo/blob/master/test/spec/InBrowser.spec.js#L355-L379

Let me know if it works as expected.

0reactions
JonasTauliencommented, Apr 25, 2017

Wow, that was fast! I really like your usage of the strategy pattern here 😃 I had a look at the implementation and the test - And I don’t know why it would not work as expected.

Thank you really much, Krasimir, for taking the time to resolve this issue!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Relative and absolute paths, in the file system and on the web ...
So it goes for the paths in the computer world: given the absolute address, you can always get to the place, no matter...
Read more >
Absolute vs Relative Path - Which Should You Be Using?
Absolute paths contain a complete URL, which includes a protocol, the website's domain name and possibly a specific file, subfolder, or page ......
Read more >
HTML: Lesson 3 - CIS - MSJC
An absolute path is a resource reference that will always be correct no matter where the HTML file with the hypertext link is...
Read more >
Understanding HTML File Paths & How to Use Them
Learn about the differences between absolute and relative HTML file paths and how you can use them to improve your web development skills....
Read more >
Absolute vs Relative URLs: when to use which for SEO?
When should you use an absolute URL, and when a relative URL? ... domain ( example.com ), and path (which includes the directory...
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