I am using Angular 13 and I am trying to subscribe to the ActivatedRoute 'fragment'. The subscription is only receiving a notification when the page first loads, but is not receiving updates when the fragment gets updated.
Here is an example of what I am doing:
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
@Component({
selector: 'app-my-component',
templateUrl: './my-component.component.html'
})
export class MyComponentComponent implements OnInit {
constructor(private activatedRoute: ActivatedRoute) { }
ngOnInit(): void {
this.activatedRoute.fragment.subscribe((fragment: string) => {
console.log("test page: ", fragment)
});
}
}
I would expect that on page load, and every time the fragment changes I would receive a notification to this subscription.
What I am actually experiencing is that this subscription is only notified on the initial page load, and not on any subsequent changes.
you need to subscribe to the router events: