javascript – Uncaught(在promise中):TypeError:无法读取null的属性’component’
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了javascript – Uncaught(在promise中):TypeError:无法读取null的属性’component’,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2124字,纯文字阅读大概需要4分钟。
内容图文
![javascript – Uncaught(在promise中):TypeError:无法读取null的属性’component’](/upload/InfoBanner/zyjiaocheng/701/f228a78a358b4026b7e5661b7ca652bc.jpg)
尝试在Angular 4中使用nestet路由时出现此错误:
ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'component' of null
TypeError: Cannot read property 'component' of null
at PreActivation.webpackJsonp.../../../router/@angular/router.es5.js.PreActivation.traverseRoutes (http://localhost:4200/vendor.bundle.js:77976:71)
at http://localhost:4200/vendor.bundle.js:77954:19
at Array.forEach (native)
at PreActivation.webpackJsonp.../../../router/@angular/router.es5.js.PreActivation.traverseChildRoutes (http://localhost:4200/vendor.bundle.js:77953:29)
at PreActivation.webpackJsonp.../../../router/@angular/router.es5.js.PreActivation.traverseRoutes (http://localhost:4200/vendor.bundle.js:77985:22)
这是我的路由代码:
const appRoutes: Routes = [
{
path: '',
component: HomeComponent
},
{
path: 'sobre',
component: SobreComponent
},
{
path: 'c/:concurso', component: ConcursoItemComponent
, children: [
{
path: ':cargo',
component: CargoItemComponent,
children: [
{
path: ':disc',
component: DisciplinaItemComponent,
children: [{
path: ':assunto',
component: AssuntoItemComponent
}]
}
]
}
]
},
];
我想制作以下嵌套规则,每个规则使用变量来通知每个路由的嵌套组件:
/
/ C /:concurso /
/ C /:concurso /:货物/
/ C /:concurso /:货物/:盘/
/ C /:concurso /:货物/:盘/:ASSUNTO
在每个级别上,我将需要所有上层变量来正确查询API的相关对象.
谢谢你的帮助!
解决方法:
正如本文(https://angular-2-training-book.rangle.io/handout/routing/child_routes.html)所述,当处理子路由时,就像为应用程序的根定义路由器出口一样,您必须为父组件定义路由器出口(在本例中为ConcursoItemComponent.技术上也是CargoItemComponent& DisciplinaItemComponent)所以你有2个选择.
>在ConcursoItemComponent中定义路由器插座.这样,当用户访问c /:concurso /:cargo时,路由器将知道加载子组件(CargoItemComponent)的位置
>不要使用子路由,而是将所有路由设置在顶级路由器级别(应用程序的根目录)
{
path: 'c/:concurso,
component: ConcursoItemComponent
},
{
path: 'c/:concurso/:cargo,
component: CargoComponent
},
{
path: 'c/:concurso/:cargo/:disc,
component: DisciplinaItemComponent
},
{
path: 'c/:concurso/:cargo/:disc/:assunto,
component: AssuntoItemComponent
}
这样,路由器将始终将组件插入应用程序根目录的路由器出口.
内容总结
以上是互联网集市为您收集整理的javascript – Uncaught(在promise中):TypeError:无法读取null的属性’component’全部内容,希望文章能够帮你解决javascript – Uncaught(在promise中):TypeError:无法读取null的属性’component’所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。