It's possible to create childRouter inside the widget that can be re-used in other page again by using a widget?
This is how my directory tree looks like:
* app
* views
* dashboard (route: /dashboard)
- dashboard.html
- dashboard.js
* shells
* projects (route: /projects)
* widgets
* timeline
- view.html
- viewmodel.js
* child
- all.html
- all.js
- task.html
- task.js
What i want to do is:
Inside a timeline widget i want to have several tab.
e.g: [ ALL ] and [ TASK ]
Then, i will can use that widget on /dashboard and /projects page.
for example if I currently use that widget inside /dashboard page then when I click any tab button inside a widget (for this case let's say i click on tasks tab button) it will change a current url from 'localhost/dashboard' to 'localhost/dashboard/tasks' (without refresh a page). Then it will show a view from /widgets/timeline/child/tasks inside a widget.
So, it will be vice versa if I use that widget inside /projects page, it will change current url from 'localhost/projects' to 'localhost/projects/tasks'
This is what i've tried so far:
Inside timeline.js widget:
var parentModuleId = router.activeItem()['__moduleId__'];
var childRouter = router.createChildRouter().makeRelative({
fromParent: true,
moduleId: parentModuleId
}).map([
{ route: ['all', ''], moduleId: 'widgets/timeline/child/all', title: 'Show All', nav: true },
{ route: 'tasks', moduleId: 'widgets/timeline/child/tasks', title: 'Tasks', nav: true },
]).buildNavigationModel();
Inside timeline.html widget:
<section>
<div class="panel panel-default">
<div class="panel-heading" data-bind="foreach: router.navigationModel">
<a data-bind="attr: { href: hash, title: title }" class="btn btn-primary btn-lg">
<span data-bind="text: title"></span>
</a>
</div>
</div>
<div data-bind="router: { router: router }"></div>
</section>
And inside dashboard.html or projects.html:
<div>
<div data-bind="widget: { kind: 'timeline' }"></div>
</div>
But it seems doesn't work..
Any help or idea and suggestions will greatly appreciated!
Thanks