justinfagnani / route

A client + server routing library for Dart
BSD 3-Clause "New" or "Revised" License
114 stars 40 forks source link

Add default handler support #42

Closed yissachar closed 10 years ago

yissachar commented 11 years ago

It would be nice to have support for a default route handler that would be invoked when no other routes were matched. For instance, something like the following:

 var router = new Router()
..addHandler(homeUrl, showHome)
..addHandler(articleUrl, showArticle)
..addDefaultHandler(showDefaultPlace)
..listen();

If the URL does not match homeUrl or articleUrl, showDefaultPlace will be called.

Currently in order to achieve this behaviour, a handler that matches all routes would have to be created and then URLs could be matched against them (as outlined in my StackOverflow answer). This is a messy workaround and it would be much cleaner to have built-in support.

pavelgj commented 11 years ago

If you're feeling adventurous take a look at this branch where default routes are already implemented: https://github.com/dart-lang/route/tree/experimental_hierarchical

(WARNING: as the name suggests, it is experimental, so API is subject to change without warning)

yissachar commented 11 years ago

Oh, very cool. Looks like this solves a few other things that I was going to complain about, so I'm looking forward to playing with it.