Skip to content

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

@sugacube

Description

@sugacube

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()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions