View doesn't seem to be the right place even though it is easy to drom
- It gathers all initializations in a single place, so you don't need to search for code through all views.
- It uses URL path to determine state of your applications - exactly what URL was designed for.
Defining handler callbacks inline while define routes.
router = new RouteJS() router.map (match, done)-> match('/page/:slug').to (params) -> # Do whatever you need on this page. params.slug is available match('/country/:country_id/city/:id').to (params) -> # Do whatever you need on this page. params.country_id, params.id are available done()
Pre-defined object with handler callbacks, to simplify routes description.
handlers = findPage: (params) -> .... findCity: (params) -> .... router = new RouteJS(handlers) router.map (match, done)-> match('/page/:slug').to('findPage') match('/country/:country_id/city/:id').to('findCity') done()
ALL routes before and after callbacks
router = new RouteJS() router.before -> # Run before all routes router.after -> # Run after all routes router.map (match, done) -> .......... done()