J'essaie de naviguer vers le composant listProfiles via le composant de profil (le composant précédent). J'utilise un ActivatedRoute
et j'essaie d'y accéder via this.router.navigate(['/listProfiles
])
Code dans le composant qui doit naviguer vers le composant listProfile
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]
})
vous devez ajouter:
constructor(private route:ActivatedRoute,private router:Router) { }
puis :
this.router.navigate(...