angular - 导航到组件路由时出错
问题描述
我正在使用带有打字稿的 Angular 6,并尝试使用导航从一个组件路由(RegisterComponent)导航到另一个组件路由(ProfileComponent)(使用 routerLink 也不起作用)。我尝试了很多我发现的例子,但我一直遇到同样的错误:
错误错误:未捕获(承诺中):TypeError:无法读取未定义的属性>'removeEventListener' TypeError:无法读取未定义的属性'removeEventListener'
我的代码:
app.module.ts
import { RouterModule, Routes } from '@angular/router';
//hidden imports ...
export const appRoutes: Routes = [
{path: '', component: RegisterComponent},
{path: 'profile', component: ProfileComponent},
]
@NgModule({
declarations: [
AppComponent,
RegisterComponent,
ProfileComponent,
],
imports: [
BrowserModule,
RouterModule.forRoot(appRoutes),
HttpClientModule,
FormsModule,
ReactiveFormsModule,
CustomFormsModule,
BrowserAnimationsModule,
],
providers: [],
bootstrap: [AppComponent],
exports: [ RouterModule]
})
export class AppModule { }
app.component.html
<router-outlet></router-outlet>
注册组件.ts
import { Router, ActivatedRoute } from '@angular/router';
export class RegisterComponent {
constructor(private router: Router, private route: ActivatedRoute) { }
test(){
this.router.navigate(["../profile"], {relativeTo: this.route});
//this.router.navigate(["/profile"], {relativeTo: this.route});
}
}
register.component.html
<div (click)="test()">click</div>
解决方案
推荐阅读
- javascript - 为什么脚本标签会自动将 & 转换为 &?
- javascript - 读取并回显图像文件 Node.js
- pytest - pytest ScopeMismatch 异常
- python - 有没有办法使用 pandas.cut() 函数选择垃圾箱的上端?
- google-my-business-api - 过期时如何在google mybusiness中重置令牌api?
- keycloak - 如何将moodle与keycloak连接起来
- elasticsearch - 在包含路径值的字段上使用通配符过滤器进行弹性搜索查询
- haskell - haskell: cd 命令在shake/command 库中不起作用
- python - 如何使用逐元素数据框操作?
- java - Apache GraphX 分区策略正在生成错误