在角度2中,如何检测路线变化 [英] In angular 2 how do you detect route changes
本文介绍了在角度2中,如何检测路线变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我当前使用旧库的尝试.
This is my current attempt using the old libraries.
我正在使用最新的库,我将如何更新它:
import { Component, } from '@angular/core';
import { Location } from '@angular/common';
import { Router } from '@angular/router';
@Component({
moduleId: module.id,
selector: 'HeaderComponent',
templateUrl: 'header.component.html'
})
export class HeaderComponent{
router : Router;
constructor(router: Router, location: Location){
this.router = router;
this.router.changes.subscribe((currentRoute) => {
let currentRoute = this.location.path();
})
}
}
这是我的模块:
export * from './header.component';
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RouterModule } from '@angular/router';
import { HeaderComponent } from './header.component';
@NgModule({
imports: [RouterModule, CommonModule],
declarations: [HeaderComponent],
exports: [HeaderComponent],
providers: []
})
export class HeaderModule { }
推荐答案
在新路由器中,它是
this.router.events.subscribe(...)
另请参见 Angular 2路由器事件侦听器
这篇关于在角度2中,如何检测路线变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文