Allows you to map "controllers" to routes.
var AmpRouter = ;var myRouter =// A map of controller constructors. Name is important.controllers:index:profile:// Passed to the controller constructor. I use this to pass a reference to// my "app" object for example:controllerOptions:app: appInstance// Function passed to the route action. I use this to update the current view// and stuff.routeCallback: appInstancerouteHandler// And finally your actual routes. Remember that leading `/` is not necessary// and won't actually do what you think.routes:'': 'index.home' // On `/` execute the `home` method on the `index` controller'/profile': 'profile.user';// Start the router.// Accepts the same arguments as the original `ampersand-router`. But has// slightly different defaults://// pushState: true// hashChange: false// silent: false// root: '/'//// This means that `start()` will execute the _current_ URL and won't use # for// routing but rather "real" URLs.myRouterstart;
This router extends the original ampersand-router and all the same events etc should be emitted.
I usually make my "controllers" subclasses of
ampersand-state. And the
method will call the callback with an error or an instance of an
So something like this:
var AmpState = ;moduleexports = AmpState;
That's a sample of how I use this. For some history on it's origins check out my blog post building an app with Ampersand.
This is a very thin wrapper (~70 LOC including comments) around
It currently has no tests but have been working fine for me! :)