【问题标题】:aurelia child route with "settings" parameter带有“设置”参数的 aurelia 子路由
【发布时间】:2017-06-12 14:18:37
【问题描述】:

我需要使用 aurelia 路由器将一些 设置 添加到子路由。

如果我将 settings 参数添加到主路由,当导航管道通过 授权步骤 时,我可以使用 navigationInstruction 检索设置。 config.settings 属性。

当导航到子路由时,authorizeStep 获取主路由的路由信息​​及其 settings 以及关于子路由的一些信息但没有设置...

例如: 如果我在 app.ts

中定义了以下主要路线
{name: 'user', settings: {bla: 'user'}...}

以及 user.ts 中定义的以下子路由:

{name: 'useredit', settings: {bla: 'edit'}...}

无论我导航到 user 还是 useredit 路由,我总是得到以下设置对象:{bla: 'user'} as导航指令与主要路线有关。

导航到 edit 时如何获取 {bla: 'edit'} 设置信息?

我当然希望答案不仅仅是“子路由不能有设置”... :)

谢谢!

【问题讨论】:

  • 通过调用navigationInstruction.getAllInstructions(),你应该得到2条指令。第一个与主路由相关,第二个与包含settings: {bla: 'edit'} 的子路由相关。这能解决你的问题吗?
  • 太棒了!我不知道那个功能,它完全解决了我的问题!如果您将评论转换为答案,我很乐意接受。谢谢!

标签: router aurelia


【解决方案1】:

通过调用navigationInstruction.getAllInstructions(),您应该得到 2 条指令。第一个与主路由相关,第二个与子路由相关,其中包含设置:{bla: 'edit'}。例如:

class AuthorizeStep {
  run(navigationInstruction, next) {
    // all the instructions here!
    let instructions = navigationInstruction.getAllInstructions();
    // ... do something
    return next();
  }
}

希望这会有所帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-07-11
    • 1970-01-01
    • 2023-04-04
    • 1970-01-01
    • 1970-01-01
    • 2019-07-06
    • 2017-12-15
    相关资源
    最近更新 更多