Coder Social home page Coder Social logo

"Route not found" event about router5 HOT 10 CLOSED

router5 avatar router5 commented on May 3, 2024
"Route not found" event

from router5.

Comments (10)

ivan-kleshnin avatar ivan-kleshnin commented on May 3, 2024

Ooops, I see it's even stranger.

Invoking the .start([startPathOrState ,] done) function will:
Navigate to the default route if the current URL does not match an existing route

First. It's not documented how startPathOrState variable should affect.
Ok, let's skip this for a moment...

I have this code:

import {Router5} from "router5";

let router = new Router5(undefined, {
  useHash: false,      
  defaultRoute: "ginger",
});

router
  .addNode("home", "/")
  .addNode("ginger", "/ginger");

function handleAll(toState, fromState) {
  console.log("handleAll()");
  console.log("toState:", toState);
  console.log("fromState:", fromState);
}

router.addListener(handleAll);
router.start();

Let's try what this code does at access to http://localhost:3000/sdfdsf...

It suddenly redirects me to http://localhost:3000/sdfdsf/ginger 😧

Expected (at least to me) behavior would be to raise "Not found" event.
But... even following the docs... why not "http://localhost:3000/ginger"?

Is this a bug or... magic?

from router5.

troch avatar troch commented on May 3, 2024

For not found: http://router5.github.io/docs/transition.html

Error: .onTransitionError(cb), .offTransitionError(cb)
Listeners are of the following form: function (toState, fromState) { }. Transition error listeners are called with an extra err argument.

from router5.

troch avatar troch commented on May 3, 2024

http://localhost:3000/sdfdsf => http://localhost:3000/sdfdsf/ginger

Well it is not really a bug, but it could definitely be improved. So far the router assumes that if you managed to load http://localhost:3000/sdfdsf, then /sdfdsf might be your base path.

from router5.

ivan-kleshnin avatar ivan-kleshnin commented on May 3, 2024

@troch if I just access /sdfdsfsdf onTransitionError is not invoked because redirect-to-default-route behavior overrides it.

Next I try:

function handleErrors(err) {
  console.log("error:", err);
}
router.onTransitionError(handleErrors);
router.navigate("dfdf");

handleErrors is still not called. Nothing happens.

What am I doing wrong?

from router5.

troch avatar troch commented on May 3, 2024
function handleErrors(toState, fromState, err) {
  console.log("error:", err);
}

from router5.

troch avatar troch commented on May 3, 2024

I know why it is not called, needs to be fixed

from router5.

troch avatar troch commented on May 3, 2024

Thanks for raising those issues 👍 , a few points have been improved with 0.6.0 (just released).

from router5.

troch avatar troch commented on May 3, 2024

Oops didn't mean to reopen

from router5.

ivan-kleshnin avatar ivan-kleshnin commented on May 3, 2024

@troch, thank you for this project! I really appreciate your work.

from router5.

troch avatar troch commented on May 3, 2024

Thanks for your kind words!

from router5.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.