如何使用 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');
}
答案 0 :(得分:0)
navigateToRoute
与路由 name 一起用作参数,您正在为其提供 route
为您的“新”路由命名并使用 navigateToRoute
,或者使用 navigate('new')
,因为该方法将路由作为参数而不是名称