Skip to content
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

Incorrect path detection #191

Closed
eugeniumegherea opened this issue Feb 9, 2018 · 2 comments
Closed

Incorrect path detection #191

eugeniumegherea opened this issue Feb 9, 2018 · 2 comments

Comments

@eugeniumegherea
Copy link

Hello.
Today found some ugly bug.
Sample:
router.on({ '/search/:v/:q': { as: 'search', uses: function () { console.log('search', arguments[0]); } }, '/locations': { as: 'home', uses: function () { console.log('root'); } } });

The route search will never work if in its parametrized url will be string '/locations', which is another route path. The callback is never called
In other words, navigation to http://127.0.0.1:8080/#/search/locations/d does not trigger callback, however, http://127.0.0.1:8080/#/search/notlocations/d will work

@buff32
Copy link

buff32 commented May 13, 2018

I'm interested in working on a PR for this, but I've not been able to replicate it in either Chrome or Firefox.

This is the test page I've used:

<!DOCTYPE html>
<html>
  <head>
    <title>Navigo test</title>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/navigo.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script>
    $(function() {
      var router = new Navigo(null, true, '#');

      router.on(
        {
          '/search/:v/:q': {
            as: 'search',
            uses: function () {
              console.log('search', arguments[0]);
            }
          },
          '/locations': {
            as: 'home',
            uses: function () {
              console.log('root');
            }
          }
        }
      );

      router.resolve();
    });
    </script>
  </head>
  <body></body>
</html>

Console outputs accessing "#/search/notlocations/d":
search {v: "notlocations", q: "d"}

Similarly, for "#/search/locations/d":
search {v: "locations", q: "d"}

Could you provide some sample code that demonstrates the problem please?

krasimir pushed a commit that referenced this issue Dec 27, 2020
@krasimir
Copy link
Owner

There is a new version 8.0.0 of the library and the bug can't be reproduced there. Navigo got re-written so probably the new implementation fixed the problem. Here's an example which works as expected:

<div>
  <a href="/search/locations/d" data-navigo>one</a>
  <a href="/search/notlocations/d" data-navigo>two</a>
</div>
<hr />
<div id="content"></div>
<script src="/navigo.js"></script>
<script>
  window.addEventListener("load", () => {
    const router = new Navigo("/");
    const render = (content) =>
      (document.querySelector("#content").innerHTML = content);

    router.on({
      "/search/:v/:q": {
        as: "search",
        uses: function (match) {
          render("Search " + JSON.stringify(match.data));
        },
      },
      "/locations": {
        as: "home",
        uses: function () {
          render("Home");
        },
      },
    });
  });
</script>

P.S.
Version 8.0.0 is not officially released but can be installed via npm install navigo@beta or yarn add navigo@beta. Migration guide is available here https://github.com/krasimir/navigo/blob/big-rewrite/CHANGELOG.md#migration-guide and the new documentation here https://github.com/krasimir/navigo/blob/big-rewrite/DOCUMENTATION.md.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants