ramiel / router.js

Router.js is a simple and powerful javascript library to handle routing
116 stars 21 forks source link

Can the routing module have some hooks to get the last route of the current routing? #23

Closed caihuattkl closed 6 years ago

caihuattkl commented 6 years ago

Can the routing module have some hooks to get the last route of the current routing?

caihuattkl commented 6 years ago

I want to get the last route that can't be realized?

ramiel commented 6 years ago

Do you mean you want to execute a function when no route matches the current URL?

caihuattkl commented 6 years ago

Yes, it's one of the needs。

ramiel commented 6 years ago

So you can use the error handler for the 404 case

router
  .errors(404, function( err, href){
    alert('Page not found!' + href );
  });

this will match any unmatching route and you have access to href in the handler

caihuattkl commented 6 years ago

Thank you. It's beginning to understand.

ramiel commented 6 years ago

Great!