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

The 'before' hook can be triggered for links without 'data-navigo' for hash based navigation with a default route. #336

Open
sugacube opened this issue Dec 19, 2023 · 0 comments

Comments

@sugacube
Copy link

The before hook appears to be triggered when a link without 'data-navigo' clicked in some special situations, for example with hash based navigation with a default route.

how to reproduce

foollowing html :

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Navigo</title>
    <link href="/styles.css" rel="stylesheet" />
  </head>
  <body>
    <ul>
      <li><a href="/about" data-navigo>About</a></li>
      <li><a href="#">Other</a></li>
    </ul>
    <div id="content"></div>
    <script src="/navigo.js"></script>
    <script>
      function defaultroute() {console.log('defaultroute clicked')}
      function aboutroute() {console.log('aboutroute clicked')}
      window.addEventListener("load", () => {
        const router = new Navigo("/",{hash: true, strategy: 'ONE'});
	router.hooks({
		before(done, match) {console.log('router before hook', match);done();}
	});
        router
          .on("/about", aboutroute)
          .on("*", defaultroute)
          .resolve();
      });
    </script>
  </body>
</html>

A click on 'other' link fires the before hook, altough it does not have 'data-navigo' attribute.

Inspecting with F12 shows the 'Other' link does not have an event handler (the 'about' link does) , so seems to be triggered by top level event handler calling resolve()

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

1 participant