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]
})
ActivatedRoutelink. Provides access to information about a route associated with a component that is loaded in an outlet.
The ActivatedRoute is the API that holds observable data that you can use to react to events with. You can subscribe to specific observable properties to get data from it asynchronously. The ActivatedRoute also contains ActivatedRouteSnapshot.
you have to add :
constructor(private route:ActivatedRoute,private router:Router) { }
then :
this.router.navigate(...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With