Skip to content
Tom Clement edited this page Sep 27, 2016 · 1 revision

The router subscribes to page URL changes, executes controller methods for the current URL route, and was designed to do its work in the background without having to know how its internals work precisely. We'll discuss the use cases where you'll interact with it here.

Usage inside the App class

Configuring the app's default route

This configures what controller method to run if the current URL does not contain a route. This happens on app startup, for example. You can pass in either a controller constructor (a class), a controller instance (an object), or a controller name (a string) for the controller parameter. The method name should be a string. Keep in mind that this string is case-sensitive.

router.setDefault('Home', 'Index');

Setting up controller animation specs

When the currently displayed view changes, the router will trigger an animation between the current view and the view to be displayed. You can influence this animation by giving the router a Controller Specification, which lists the animations to use from each location to a given controller:

router.setControllerSpecs(ControllerSpecification);

You can read what the Controller Specification object should look like in the Page Animations section.

Usage inside Controllers

Navigation

Navigating to another controller method is super easy. Check this out:

router.go('Demo', 'someMethod', {param1: 'value1', param2: 2});

This changes the page URL to #/Demo/someMethod along with the parameters, and calls DemoController.someMethod('value1', 2);. This then loads and animates the view that method returns.