title: How to get params from url using Router or ActivatedRoute in angular
body: <p>I'm trying to get parameters from url in AppComponent in my angular application. </p>
  
  <p>But when I use ActivatedRoute to get params it gives null. This is my router configuaration.</p>
  
  <pre><code>  {
      path: '',
      component: HomeComponent,
      canActivate: [AuthGuard]
    },
    {
      path: 'product/:product',
      component: HomeComponent,
      canActivate: [AuthGuard]
    }
  </code></pre>
  
  <p>This is what I tried in AppComponent to get the the result of params from url.</p>
  
  <pre><code>constructor(
        private route: ActivatedRoute,
        private router: Router
  ) {}
  
  ngOnInit() {
  
  this.route.params.subscribe(params =&gt; {
        console.log(params['product']); //jsut print the result in console
  });
  
  //or can use to get the result
  //console.log(this.route.snapshot.params['product'];
  
  }
  </code></pre>
  
  <p>this code only works inside particular components. So, Is there any suitable way to get the results.
  [Angular 6+]</p>