O'Reilly logo

Mastering KnockoutJS by Timothy Moran

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using the router

While technically an optional plugin, I don't imagine any real-world SPAs will do without the use of the router. While SammyJS ties a URL fragment to a function, Durandal's router ties the URL directly to a module ID. The module can return either a singleton or a constructor, and will be used to bind the view using the standard composition system.

Configuring the router

Let's start configuring the router:

  1. Route configuration is pretty straightforward. Here is the shell module with router configuration for the Contact application:
    define(['plugins/router', 'knockout', 'durandal/app'], function (router, ko, app) { return { title: app.title, router: router, activate: function() { router.map([ { route: '', moduleId: 'contacts/list', title: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required