Вы подписываетесь в методе OnInit или где-то еще?Я попробовал ваш пример кода, и он отлично работает на моем локальном компьютере:
app.routing.ts
import { Routes, RouterModule } from '@angular/router';
import { ModuleWithProviders } from '@angular/core';
import { ParentComponent } from './parent.component';
import { NewRouteComponent } from './new-route.component';
export const routes: Routes = [
{ path: '', component: ParentComponent },
{ path: 'parent', component: ParentComponent },
{ path: 'newroute', component: NewRouteComponent }
];
export const routing: ModuleWithProviders = RouterModule.forRoot(routes);
parent.component.ts
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
@Component({
selector: 'app-parent',
template: `<a routerLink="../newroute">Click here</a>`,
styleUrls: ['./parent.component.css']
})
export class ParentComponent implements OnInit {
constructor(private activatedRoute: ActivatedRoute) { }
ngOnInit() {
this.activatedRoute.queryParamMap.subscribe((data) => {
console.error('in subscribe', data);
});
}
}
new-route.component.ts
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
@Component({
selector: 'app-new-route',
template: `<p>new-route works!</p>
<button (click)="goBack()">Back</button>`,
styleUrls: ['./new-route.component.css']
})
export class NewRouteComponent implements OnInit {
constructor(private activatedRoute: Router) { }
ngOnInit() {}
goBack() {
this.activatedRoute.navigate(['./parent']);
}
}