I am working on an ASP.NET MVC project with the durandal template.
I am facing a problem and need some help to find the more elegant solution. I have a header bar (blue) and a sidebar (grey). Both contains an element (link) to create a new transport. In the screenshot below this is showed with the bullets 1 & 2.
My idea was to proceed like this:
#/newTransport
#detailTransport/:id
Here is the code:
var activate = function () {
var id = datacontext.createTransport();
var url = '#/detailTransport/' + id;
router.navigateTo(url);
return true;
};
So this newTransport view is not really showed, I used this to have a link allowing me to create the transport before showing it.
My problem is that it works only the first time and furthermore it seems to break the router logic someway.
I noticed that if I move the code from the activate to a button inside the view, I don't have problem anymore.
So for resume: I need to execute some code (create an entity) before navigating to the detail of this entity. My attempt (explained above) does not seems to work.
Any idea?
The first click should be a method in the viewmodel, not a route to activate and then redirect. Its likely confused on what you want. Navigatng in an activate is not std practice. Just make the first click bind to a method in the root vm. Then navigate.