Property 'navigate' does not exist on type 'ActivatedRoute'

20,151

you have to add :

constructor(private route:ActivatedRoute,private router:Router) { }

then :

 this.router.navigate(...
Share:
20,151
Fig
Author by

Fig

Updated on October 25, 2020

Comments

  • Fig
    Fig over 3 years

    I'm trying to navigate to listProfiles component through profile component (The previous component). I'm using an ActivatedRoute and trying to navigate to it through this.router.navigate(['/listProfiles])

    Code in the component that should navigate to listProfile component

    import {ActivatedRoute, Router} from '@angular/router';
    
    constructor(private router: ActivatedRoute){}
    
    deleteProfile():void{
       this.router.navigate(['/listProfiles']); //Gives the error message in the title
    }
    

    app.module.ts

    import { ListProfilesComponent } from './list-profiles/list-profiles.component';
    import { ProfileComponent } from './profile/profile.component';
    
    const appRoutes: Routes = [
    { path: 'addProfile', component: AddProfileComponent },
    { path: 'listProfiles', component: ListProfilesComponent},
    { path: 'profile/:id', component: ProfileComponent},
    { path: 'login', component: LoginComponent}
    ];
    
    @NgModule({
      declarations: [
      AppComponent,
      ListProfilesComponent,
      ProfileComponent,
      ],
      imports: [
      FormsModule,
      ReactiveFormsModule,
      NoopAnimationsModule,
      BrowserModule,
      HttpModule,
      RouterModule.forRoot(
        appRoutes,
        {enableTracing: true}
        )
      ],
      providers: [ StorageService, LoginService, ClientIDService],
      bootstrap: [AppComponent]
    })
    
  • Fig
    Fig over 6 years
    Oh ok, simple mistake, Will set as answer in a few minutes
  • Fig
    Fig over 6 years
    Because I can't do that unless the post has been up for 15 min. As I said, I will submit it as an answer in a few minutes
  • Brijesh Mavani
    Brijesh Mavani over 6 years
    @Nawrez I already described, but get's the same error.Please help.