ActivatedRoute.snapshot.paramMap not working


I trying to get a route param on startup/initial route. But it is not working.


  import { ActivatedRoute } from '@angular/router';

    private activatedroute: ActivatedRoute
  ) {}

  ngOnInit() {

    this.activatedroute.paramMap.subscribe( paramMap => {

app.module.ts (includes more than just this though)

import { Routes, RouterModule } from '@angular/router';

const routes: Routes = [
  { path: ':token', component: HelloComponent },

  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]

Then I serve my app and go to:


But my app.component.ts just console.log’s null null. Why is this not working? I feel like I have everything correct. Here is an Angular Blitz to work with:


you have written the code in app.component.ts which is the root component, but the :token is defined for the child component, so I have moved the code to the child component, one more thing to note is that in app.component.html you need to have router outlet which will display the child component, only then the token will be visible, please refer the below example.

Stackblitz example

Answered By – Naren Murali

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published