đăng ký chuyển hướng của router "thành công" sự kiện:
import {EventAggregator} from 'aurelia-event-aggregator';
import {inject} from 'aurelia-dependency-injection';
@inject(EventAggregator)
export class App {
constructor(eventAggregator) {
this.eventAggregator = eventAggregator;
}
navigationSuccess(event) {
let instruction = event.instruction;
// todo: do something with instruction...
}
attached() {
this.subscription = this.eventAggregator.subscribe(
'router:navigation:success',
this.navigationSuccess.bind(this));
}
detached() {
this.subscription.dispose();
}
}
Dưới đây là một phiên bản hơi khác nhau sử dụng ES7 chức năng ràng buộc và ES6 destructuring:
import {EventAggregator} from 'aurelia-event-aggregator';
import {inject} from 'aurelia-dependency-injection';
@inject(EventAggregator)
export class App {
constructor(eventAggregator) {
this.eventAggregator = eventAggregator;
}
navigationSuccess({ instruction }) {
// todo: do something with instruction...
}
attached() {
this.subscription = this.eventAggregator.subscribe(
'router:navigation:success',
::this.navigationSuccess);
}
detached() {
this.subscription.dispose();
}
}
Nguồn
2015-11-13 13:35:39
thứ tốt đối với những người trong chúng ta xây dựng nav bằng tay - cảm ơn bạn – mujimu