带有 "settings" 参数的 aurelia 子路由

aurelia child route with "settings" parameter

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

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

的设置

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

例如: 如果我在 app.ts

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

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

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

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

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

我当然希望答案不会只是 "child routes cannot have settings"... :)

谢谢!

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

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

希望对您有所帮助!