Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In the code above there's truly only one route <code>'grid/:page'</code>. By defining a parameterized route the router maps everything the match <code>grid/:page</code> to the first route. See more about that in the router documentation <a href="http://durandaljs.com/documentation/Using-The-Router/" rel="nofollow">http://durandaljs.com/documentation/Using-The-Router/</a>.</p> <p>Instead of using the <code>router.navigationModel()</code> build your own small navigation model.</p> <p>Top level down approach:</p> <p><strong>Step 1</strong> Defining a <code>grid</code> route with an optional parameter <code>(/:page)</code>. </p> <pre><code>router .makeRelative({moduleId: 'viewmodels'}) .map([ { route: 'grid(/:page)', title: 'grid page', moduleId: 'grid', hash: '#grid' } ]) .buildNavigationModel(); </code></pre> <p><strong>Step 2</strong> Navigation model</p> <pre><code>define(['plugins/router', 'knockout', './navItem'], function( router, ko, NavItem ) { var ctor = function(){ this.childRouter = router; this.param = ko.observable(''); this.navigation = ko.observableArray([ new NavItem({title: 'Title 1', param: 'param1'}), new NavItem({title: 'Title 2', param: 'param2'}), new NavItem({title: 'Title 3', param: 'param3'}), new NavItem({title: 'Title 4', param: 'param4'}) ]); }; ctor.prototype.activate = function(param){ this.param('Param: ' + (param || 'no param!')); }; return ctor; }); </code></pre> <p><strong>Step 3</strong> Navigation item model</p> <pre><code>define(['plugins/router'], function( router ) { var ctor = function(options){ this._options = options || {}; this.init(this._options) }; ctor.prototype.init = function(options){ this.title = options.title; this.param = options.param; this.hash = '#extras/optional/' + this.param; }; ctor.prototype.isActive = function(){ return router.activeInstruction().fragment === this.hash.replace('#', ''); }; return ctor; }); </code></pre> <p><strong>Step 4</strong> Navigation view</p> <pre><code>&lt;div class="navbar"&gt; &lt;div class="navbar-inner"&gt; &lt;ul class="nav" data-bind="foreach: navigation"&gt; &lt;li data-bind="css: { active: isActive() }"&gt; &lt;a data-bind="attr: { href: hash }, html: title"&gt;&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt; &lt;div class="loader pull-right" data-bind="css: { active: childRouter.isNavigating }"&gt; &lt;i class="icon-spinner icon-2x icon-spin"&gt;&lt;/i&gt; &lt;/div&gt; &lt;/div&gt; &lt;div&gt; &lt;h3 data-bind="text: param"&gt;&lt;/h3&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>Live version can be seen at: <a href="http://dfiddle.github.io/dFiddle-2.0/#extras/optional" rel="nofollow">http://dfiddle.github.io/dFiddle-2.0/#extras/optional</a>. Feel free to fork and adjust to your liking.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload