【问题标题】:How to Navigate to another view by a button click如何通过单击按钮导航到另一个视图
【发布时间】:2021-07-03 16:18:31
【问题描述】:

如何使用 Aurelia 中的按钮单击导航到另一个视图?

我的代码

 <button class="btn btn-success " click.delegate="save()" >New item</button>

TS

   configureRouter(config: RouterConfiguration, router: Router){
    config.title = 'Contacts';
    config.options.pushState = true;
    config.options.root = '/';
    config.map([
      { route: '',   moduleId: PLATFORM.moduleName('no-selection'),   title: 'Select' },
     { route: 'contacts/:id',  moduleId: PLATFORM.moduleName('contact-detail'), name:'contacts' },

     { route: 'new', moduleId: PLATFORM.moduleName('new-contact-detail'),    nav: true }
]);

this.router = router;
 }

save() {
console.log("Button Clicked");
this.router.navigateToRoute('new');


  }

【问题讨论】:

  • 您好,目前尚不清楚您要做什么。您能否在 github 或沙箱中提供对您代码的访问权限,以便我们能够提供帮助?最好的问候。

标签: typescript aurelia


【解决方案1】:

navigateToRoute 与路由 name 作为参数一起使用,您正在为其提供 route

为您的“新”路由命名并使用navigateToRoute,或使用navigate('new'),因为该方法将路由作为参数而不是名称

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-25
    相关资源
    最近更新 更多