How to dynamically display tabs for routes in Dura

2020-04-20 04:28发布

This is a two part question. Am very new to durandal and knockout.

Using the HTML Starter Kit example for Durandal 2.0.1.

I add a route for customers/:id with my own vm and view with nav = false

 { route: 'customer/:id', moduleId: 'viewmodels/customer/customer', nav: false }

Because nav is false, it doesn't get used when buildNavigationModel() is called. So the shell.html doesn't show a tab entry for it. So far so good.

  1. When I navigate to c:\temp\index.html#customer/123 I can see the page, but it doesn't get included in the tabs at the top of the page. When I look at shell.html it uses data-bind to get the routes to display in those tabs. So shouldn't it display this new route I just moved to? If I set the routes, nav to true, would that be enough to refresh the shell display? Or am I failing at my first attempt to understand ko?

  2. So I have a route for customer/:id. If I go to index#customer/123 I want to see a new tab as of part 1 above. If I navigate to index#customer/234, I want to see a new tab for that as well. The user should then be able to move between the two tabs. Can this work, or is it really only recording the customer/:id route and I will only ever see one tab button?

1条回答
Lonely孤独者°
2楼-- · 2020-04-20 04:29

The router navigation model won't do what you're looking for. Check out Durandal 2.0 routing parameterized routes (same route different parameter) to see an example how to build your own navigation model instead.

查看更多
登录 后发表回答