“ActivatedRoute”类型中不存在“导航”属性

时间:2017-10-25 09:28:57

标签: angular angular-ui-router url-routing

我正在尝试通过配置文件组件(上一个组件)导航到listProfiles组件。我正在使用ActivatedRoute并试图通过this.router.navigate(['/listProfiles])

导航到它

应导航到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]
})

1 个答案:

答案 0 :(得分:9)

你必须添加:

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

然后:

 this.router.navigate(...