3

In Durandal, I have map router

router.map([
    { route: 'tickets/:id',      moduleId: 'tickets/thread', nav: true }    
]).buildNavigationModel();

I have link in address bar

http://localhost:8083/#tickets/ticket001

In my viewModel, how can i get the value of id?

Stiger
  • 1,189
  • 2
  • 14
  • 29

2 Answers2

3

You can also get them via the activate function on your view model. All parameters in the router will be passed as arguments to your activate function. see the "Route Parameters and Query Strings" section in the router docs:

http://durandaljs.com/documentation/Using-The-Router.html

Frank
  • 2,178
  • 2
  • 17
  • 24
  • I have found that the args are passed as strings (which makes sense) but that is not picked up when using TypeScript. So despite having an arg declared as a `number`, the value is a string. Fun times. – Neil Barnwell Sep 23 '15 at 01:35
2

I found the anwers, use route plugin:

define(['knockout', 'plugins/router'],
function (ko, router) {
    return {
        param = router.activeInstruction().params[0]
    };
});
Stiger
  • 1,189
  • 2
  • 14
  • 29
  • Using ```router.activeInstruction().queryParams``` is better and more consistent. Because if you use querystring on multiple pages after each other, the query params can be on ```params[1]``` – Mason Dec 07 '17 at 14:37