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

"Route not found" event #22

Closed
ivan-kleshnin opened this issue Sep 4, 2015 · 10 comments
Closed

"Route not found" event #22

ivan-kleshnin opened this issue Sep 4, 2015 · 10 comments
Labels

Comments

@ivan-kleshnin
Copy link

Suppose we're on the page /about which is not declared in the routes.
We want to display "page-not-found" widget (component) in this case.
We add listeners but router is silent if no routes matched. Why?

Shouldn't it raise an event with some special toState or toState == undefined right after router.start() to notify about this case? I was pretty sure Not found is the same valid and crucial information as Found to listen to. Did I miss something in the docs?

@ivan-kleshnin ivan-kleshnin changed the title Did not match event "Route not found" event Sep 4, 2015
@ivan-kleshnin
Copy link
Author

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?

@troch
Copy link
Member

troch commented Sep 4, 2015

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.

@troch
Copy link
Member

troch commented Sep 4, 2015

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.

@ivan-kleshnin
Copy link
Author

@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?

@troch
Copy link
Member

troch commented Sep 4, 2015

function handleErrors(toState, fromState, err) {
  console.log("error:", err);
}

@troch
Copy link
Member

troch commented Sep 4, 2015

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

@troch
Copy link
Member

troch commented Sep 4, 2015

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

@troch troch reopened this Sep 4, 2015
@troch
Copy link
Member

troch commented Sep 4, 2015

Oops didn't mean to reopen

@troch troch closed this as completed Sep 4, 2015
@troch troch added the bug label Sep 4, 2015
@ivan-kleshnin
Copy link
Author

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

@troch
Copy link
Member

troch commented Sep 5, 2015

Thanks for your kind words!

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

No branches or pull requests

2 participants