admin管理员组文章数量:1328574
I am using Aurelia framework. I want to fetch navigationInstruction info in app file(app.ts/app.js) every time user navigate to new route/page.
I have tried to fetch this information in the life-cycle events(activate and bind) of app, but no information is available.
Can anybody help me to solve this issue.
Thanks in advance.
I am using Aurelia framework. I want to fetch navigationInstruction info in app file(app.ts/app.js) every time user navigate to new route/page.
I have tried to fetch this information in the life-cycle events(activate and bind) of app, but no information is available.
Can anybody help me to solve this issue.
Thanks in advance.
Share Improve this question asked Nov 13, 2015 at 9:30 AnkurAnkur 7408 silver badges28 bronze badges1 Answer
Reset to default 10subscribe to the router's navigation "success" event:
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();
}
}
Here's a slightly different version using ES7 function binding and 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();
}
}
本文标签: javascriptIdentify the current route in AureliaStack Overflow
版权声明:本文标题:javascript - Identify the current route in Aurelia - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742215727a2434531.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论