Ramakrishna N
Ramakrishna N

Reputation: 21

Angular4 --previous page doesn't refresh when navigate back from current page

Methods in Oninit function are not invoked second time when navigate back to the same page with same route.

Upvotes: 2

Views: 1247

Answers (2)

Mehrshad Farzaneh
Mehrshad Farzaneh

Reputation: 694

Use this implementation method

 import { ActivatedRoute } from '@angular/router';
    
    constructor(
        private routerActive:ActivatedRoute
      ) {}
    
    ngOnInit() {
        this.routerActive.paramMap.subscribe(paramMap => {
            if (this.router.url === "/yourURL") {

              // ***** This runs whenever your page is displayed ******

            }
        })
}

Upvotes: 2

kemsky
kemsky

Reputation: 15261

Routes are cached by default, it means you should subscribe to paramMap and trigger loading in subscribe callback, if you trigger loading from constructor or lifecycle method - it will not be invoked second time.

Upvotes: 1

Related Questions