Here are the steps I followed:
1) new asp.net mvc 4 project 2) chose the durandal spa template 3) in shell.js, added this route...
{ route: 'orders/:id', moduleId: 'viewmodels/order', nav: false }
4) added a viewmodel- order.js:
define([], function () {
var Order = (function () {
function Order() {
this.orderId = '';
}
Order.prototype.activate = function (id) {
this.orderId = id;
};
return Order;
})();
return Order;
});
5) added a view- order.html:
<h1 data-bind="text: orderId"></h1>
6) added some links to welcome.html:
<ul> <li><a href="#orders/1">Order #1</a></li> <li><a href="#orders/2">Order #2</a></li> <li><a href="#orders/3">Order #3</a></li> <li><a href="#orders/4">Order #4</a></li> </ul>
This works great, I click on one of the "order" links in the welcome page and the order view opens up. Here is a zip containing the project.
What is the best way to add the order I've just opened to the navigation bar? After clicking on an order link I'd like the navigation bar to look like this:
Durandal | Welcome | Flickr | Order #1
If I clicked on another order link I'd like the navigation bar to look like this:
Durandal | Welcome | Flickr | Order #1 | Order #2
And I'd like to be able to close an order and end up with this (after closing the first order):
Durandal | Welcome | Flickr | Order #2
Last but not least, When navigating between orders I'd like the existing view+viewmodel instances to remain intact (note: the viewmodel script returns a constructor so it's a little different than the welcome and flickr view models).
Any pointers on how to do this would be very much appreciated.
Here's a link back to this question in the Durandal Google Group