多个模型视图中的Aurelia路由器配置

时间:2015-02-12 06:41:58

标签: aurelia

是否可以从多个视图模型配置路由器?

如下所示?

class App {
  ...
  constructor(router) {
    this.router.configure(config => {
      config.map([{
        route: 'home',
        moduleId: 'home',
        nav: true
      }])
    })
  }
}

更改其他视图模型中的路由器配置:

class SomeOtherPage {
  ...
  constructor(router) {
    this.router.configure(config => {
      config.map([{
        route: 'someOtherPage',
        moduleId: 'someOtherPage',
        nav: true
      }])
    })
  }
}

1 个答案:

答案 0 :(得分:8)

来自aurelia docs

与Aurelia的所有内容一样,我们对会议提供强有力的支持。因此,您实际上可以选择动态路由而不是预先配置所有路由。以下是配置路由器的方法:

router.configure(config => {
  config.mapUnknownRoutes(instruction => {
    //check instruction.fragment
    //set instruction.config.moduleId
  });
});

您只需设置config.moduleId属性,就可以了。您还可以从mapUnknownRoutes返回一个promise,以便异步确定目标。

此外,路由器有一个addRoute方法,在您的情况下应该可以在以后添加路由。

相关问题