Title: Refresh router on component.ts
Tags: angular;firebase
Question: I want to reload my page route to refresh data stored in it. I can do this with putting routerLink on html but is there away that I can make this into a function in ts file? I have found location.reload and location.href but they refresh the whole page.
Code to retrieve message
receiveMessage(){
this.angularFiremessaging.messages.subscribe(
(payload) =&gt; {
console.log("new message received. ", payload);
this.currentMessage.next(payload);
My html
{{ (message | async)?.notification.title }}
{{ (message | async)?.notification.body}}
Comment: What kinda data you mean exactly you'd like to retrieve from router link, params?

Comment: That's what I'm trying to avoid. I don't want to refresh the whole page. I just want my router to be reloaded so my html element can be updated.

Comment: @WebDeveloper What I'm trying to do is reload a route. For example, clicking on the home option of a menu when you are already viewing the homepage would refresh the homepage.

Comment: Why to refresh all the page and not update the specific data?


Here is another answer: If you mean params, you could use the ActivatedRoute for this purpose
import { ActivatedRoute } from '@angular/router';
constructor(private route: ActivatedRoute)
ngOnInit() {
this.route.params.subscribe(params =&gt; {
//will be fired on every param change in the url
console.log('here are your params: ', params);
});
Comment for this answer: Okay, It's much better to share some code to define where the problem exactly is, would you ?
Comment for this answer: Some sort like that. I'm working on a firebase push notification and I want my notify to be displayed in foreground automatically everytime I push it. The problem is that I have to reload my router for they to show up. I'm very appreciate your help but this does not solve my problem.

Here is another answer: Try this:
this.router.navigateByUrl('/RefreshComponent', { skipLocationChange: true }).then(() =&gt; {
this.router.navigate(['Your actualComponent']);
Reference: How to Refresh a Component in Angular
Comment for this answer: Excuse me sir. Can you explain to me what is RefreshComponent? You just made up, put some randomly component in there?
Comment for this answer: Thank you. One more question sir. I don't know what is this.router is either. It's something you implement from import a service? Like ActiveRouter or Router?
Comment for this answer: "This can be achieved via a hack, Navigate to some sample component and then navigate to the component that you want to reload."
Comment for this answer: Yes you need to import router from angular constructor(private router:Router ) {

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 4, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2020:00:03/07/20', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<angular><firebase>', 'Title': 'Refresh router on component.ts', 'ViewCount': 102, 'id': 60578377, 'user_AboutMe': None, 'user_AccountId': None, 'user_DisplayName': None, 'user_Reputation': None, 'user_Views': None, 'user_id': None}}