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

notFound is not working on new page (refresh) #229

Closed
FaBeyyy opened this issue Dec 21, 2018 · 1 comment
Closed

notFound is not working on new page (refresh) #229

FaBeyyy opened this issue Dec 21, 2018 · 1 comment

Comments

@FaBeyyy
Copy link

FaBeyyy commented Dec 21, 2018

Example:

this.router
            .on({
            '/': (query) => new HomeView(hc, query),
            '/product-selector': () => new ProductSelectorView(hc),

        })
            .notFound(function (query) { console.log('404'); hc.innerHTML= '<div>404</div>'});

Also tried having the home component to an empty route like in the example but didnt work either.
Everytime i manually go to an invalid url it still fallbacks to the homeview instead of triggering the notfound handler

@krasimir
Copy link
Owner

This is now fixed in the version 8.0.0. Example here https://github.com/krasimir/navigo/tree/big-rewrite/examples/229

The code looks like this and the not-found handler is called properly:

<div>
  <a href="/" data-navigo>Home</a>
  <a href="/product-selector" data-navigo>Product selector</a>
  <a href="/dsaljkdksajfkasjkdsa" data-navigo>Not found</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({
        "/": (match) => {
          render("home");
        },
        "/product-selector": (match) => {
          render("Product selector");
        },
      })
      .notFound(() => {
        render("Not found");
      })
      .resolve();
  });
</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

2 participants