I'm currently using Angular 13 and attempting to subscribe to the ActivatedRoute 'fragment'. However, I am facing an issue where the subscription only receives a notification when the page initially loads, and does not update when the fragment changes.
Below is an example of my implementation:
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)
});
}
}
My expectation was to receive notifications from this subscription on page load and every time the fragment changes. However, the actual behavior is that the subscription is only activated on the initial page load and does not respond to subsequent changes in the fragment.