Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
MASTERING KNOCKOUTJS

You're reading from   MASTERING KNOCKOUTJS Use and extend Knockout to deliver feature-rich, modern web applications

Arrow left icon
Product type Paperback
Published in Nov 2014
Publisher
ISBN-13 9781783981007
Length 270 pages
Edition 1st Edition
Arrow right icon
Author (1):
Arrow left icon
Timothy Moran Timothy Moran
Author Profile Icon Timothy Moran
Timothy Moran
Arrow right icon
View More author details
Toc

Table of Contents (11) Chapters Close

Preface 1. Knockout Essentials FREE CHAPTER 2. Extending Knockout with Custom Binding Handlers 3. Extending Knockout with Preprocessors and Providers 4. Application Development with Components and Modules 5. Durandal – the Knockout Framework 6. Advanced Durandal 7. Best Practices 8. Plugins and Other Knockout Libraries 9. Under the Hood Index

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: 'Contacts', nav: true },
            { route: 'contacts/new', moduleId: 'contacts/edit', title: 'New Contact', nav: true },
            { route: 'contacts/:id', moduleId: 'contacts/edit', title: 'Contact Details', nav: false...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime