title: Get Previous URL in Angular
body: <p>I need Previous URL in OnInit function of Angular TS file.</p>
  
  <pre><code>ngOnInit() {
          this.router.events
              .pipe(filter((e: any) =&gt; e instanceof RoutesRecognized),
                  pairwise()
              ).subscribe((e: any) =&gt; {
                  console.log(e[0].urlAfterRedirects); // previous url
              });
      }
  </code></pre>
  
  <p>I can get by above Code, but this Repeats multiple times, because I am having lot of child component under Parent.
  I need any other method, which runs only onces</p>