我为路由模块创建了一个匹配器功能,但出现一个奇怪的错误:即使我检查对象是否存在,也无法读取null的属性'path'。
export function contentMatcher(url) { //for simplifying, assume that all checks returned true return { consumed: url, posParams: { type: new UrlSegment(url[0].path, {}), item: url[1] ? new UrlSegment(url[1].path, {}) : null //<------ Cannot read property 'path' of null } } }
const routes: Routes = [ { matcher: contentMatcher, component: ContentComponent } ]
我知道我必须导出匹配器函数,因为aot不支持函数表达式。但我不知道posParams是否也需要它,即使如此,如何将“ url”传递给它。
已解决
通过替换item: url[1] ? new UrlSegment(url[1].path, {}) : null
解决的问题与item: new UrlSegment(url[1] ?url[1].path: null, {})
我为路由模块创建了一个Matcher函数,但是出现一个奇怪的错误:即使我检查对象是否存在,也无法读取null的属性'path'。导出函数contentMatcher(url){// for ...
执行此操作的好方法是在返回之前测试url
。
执行此操作的好方法是在返回之前测试url
。