Question

The article I am looking at is Durandal Router.

Under mapAuto, it says we can pass splat parameter in the url #/customers/1. and the activate function in the viewmodel will be able to retrieve the parameter array.

I built a route here

router.mapRoute('view/:id', moduleId, 'Customer Details', false);

But how can I obtain the id in the activate function? There is no example on the doc page. Please help us out. Thank you.

Was it helpful?

Solution

Give your activate function a single parameter, perhaps named something like "data".

The id that was passed into the url will then be available within the activate function as "data.id".

var activate = function(data) {
    alert(data.id);
};
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top