Angular 2 rc3 路由器订阅
Angular 2 rc3 Router subscribe
在 angular2 rc1 中,我订阅了更改路线:
this.router.changes.subscribe(
() => {
console.log(this.location.path());
});
如何在angular2 rc3 中订阅更改路由?
router.changes 已经不存在。
constructor(router:Router) {
router.events.subscribe(event:Event => {
if(event instanceof NavigationStart) {
}
// NavigationEnd
// NavigationCancel
// NavigationError
// RoutesRecognized
}
}
或
constructor(router:Router) {
router.events.forEach(event:Event => {
constructor(private router: Router) {
this.router.events.subscribe(event => {
if (event.constructor.name === 'NavigationStart') {
console.log(event.url);
}
});
}
在 angular2 rc1 中,我订阅了更改路线:
this.router.changes.subscribe(
() => {
console.log(this.location.path());
});
如何在angular2 rc3 中订阅更改路由? router.changes 已经不存在。
constructor(router:Router) {
router.events.subscribe(event:Event => {
if(event instanceof NavigationStart) {
}
// NavigationEnd
// NavigationCancel
// NavigationError
// RoutesRecognized
}
}
或
constructor(router:Router) {
router.events.forEach(event:Event => {
constructor(private router: Router) {
this.router.events.subscribe(event => {
if (event.constructor.name === 'NavigationStart') {
console.log(event.url);
}
});
}