Home > other >  Angular not view get parameter
Angular not view get parameter

Time:10-09

I specify the route for routing.module.in ts as shown below. The link goes as if it were not.

Routes:

const routes: Routes = [


{ path: '', redirectTo: 'login', pathMatch: 'full' },
  { path: 'login', component: LoginComponent },
  { path: 'register', component: RegisterComponent },
  { path: 'activate/:code', component:ActivateComponent},
  {
    path:'reset-password' , component:ResetPasswordComponent
      },

];

Url: http://localhost:4200/activate/test

Activate Component:

export class ActivateComponent implements OnInit {
  constructor(private route:ActivatedRoute) { 

  }
  ngOnInit(): void {
    let code = this.route.snapshot.params['code'];
    console.log(code)
  }
}

CodePudding user response:

You need to subscribe to the route params. Try this:

 this.route.params.subscribe(params => {
      this.code = params['code'];            
    });

CodePudding user response:

Try this :

  let code=this.route.snapshot.paramMap.get('code')
  • Related