组合参数,splat路由和子路由器 [英] Combining parameters, splat routes and child routers

查看:96
本文介绍了组合参数,splat路由和子路由器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在尝试将路线参数与splat路线一起使用。这就是这种情况。

We are trying to use route parameters alongside splat routes. This is the scenario.

我们有一个导航菜单,然后作为一个选项的一部分,我们有一个向导。转到向导时,我们要传递正在处理的对象的标识符。同时,该向导具有步骤,我们希望在子级路由器上处理这些步骤,并将该步骤作为路由的一部分传递(*详细信息)。

We have a navigation menu, and then as part of one of the options, we have a wizard. When we go to the wizard, we want to pass the identifier for the object we are working on. At the same, the wizard has steps and we want to handle those at the child level router, passing also the step as part of the route (*details).

splat路由如下所示:

The splat route looks like this:

   { route: 'offer/:offerId/*details', moduleId: 'offerbuilder/index', title: 'Offer Builder' }

子级路线如下:

[
   { route: 'parameters', moduleId: 'parameters', title: 'Parameters', nav: true },
   { route: 'cart', moduleId: 'cart', title: 'Cart', nav: true },
   { route: 'workspaces', moduleId: 'workspaces', title: 'Workspaces', nav: true }
]

我们已经有了路由器和子路由器来适当地解析路由,但是我们遇到的问题是子级路由的哈希不能替换传递的参数值,而是使用原始模式。换句话说,这确实可行:

We've got the router and child router to resolve the routes appropriately, but the issue we are having is that the hashes for the children routes don't replace the passed parameter value, but use the original pattern. In other words, this do work:

 http://oursite/main/#offer/123456789/parameters

但作为向导步骤的一部分生成的散列为:

but the hashes generated as part of the wizard steps are:

  http://oursite/main/#offer/:offerId/parameters

我的问题是,splat路由是否支持包含参数?如果没有,建议的解决方法是什么?

My question is, do splat routes support the inclusion of parameters? If not, what would be the suggested workaround?

推荐答案

这是子路由器当前的问题,它是在此处讨论

This is currently an issue with the child router, which is discussed here.

解决方案是拉出parentId并手动为子路由器构建哈希。

The solution is to pull the parentId and manually construct the hashes for the child router.

var childRouter = router.createChildRouter()
   .makeRelative({
      moduleId: 'employees/doctors',
      route: 'doctors/:id',
   });

return {
   router: childRouter,
   activate: function() {
      var doctorID = router.activeInstruction().params;

      childRouter.map([
         { route: '', moduleId: 'patients/index', hash: '#employees/doctors' + doctorID(), nav: true },
         { route: 'schedule', moduleId: 'schedule/index', hash: '#employees/doctors/' + doctorID() + '/schedule', nav: true }
      ]).buildNavigationModel();
   }
};

这篇关于组合参数,splat路由和子路由器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆