如何调试未被捕获(在promise中):EmptyError:由router.navigate引起的序列中没有元素?

我想实现生成列表中的一些成分简单的角度路线如何调试未被捕获(在promise中):EmptyError:由router.navigate引起的序列中没有元素?

const appRoutes: Routes = [ 

{ path: '' ,redirectTo: '/recipes', pathMatch: 'full'},

{ path: 'recipes' , component: RecipesComponent},

{ path: 'recipes/:recipeName' , component: RecipesComponent},

];

,我有一个 更新点击状态变量和路径的功能,虽然我也有提取机制,用户发生在初始化。

ngOnInit() { 

this.route.params

.subscribe(

(params: {Params}) => {

this.selectedRecipe = this.findRecipeByName(params['recipeName']);

});

}

navRecipe(recipeName: string): void {

let path = '/recipes/' + recipeName;

this.selectedRecipe = this.findRecipeByName(recipeName);

this.router.navigate([path]);

}

但是,当我尝试单击重新路由到组件与参数,我得到以下的链接:

core.js:1350 ERROR Error: Uncaught (in promise): EmptyError: no elements in sequence 

EmptyError: no elements in sequence

at new EmptyError (EmptyError.js:28)

at FirstSubscriber._complete (first.js:154)

at FirstSubscriber.Subscriber.complete (Subscriber.js:122)

at MergeMapSubscriber._complete (mergeMap.js:150)

at MergeMapSubscriber.Subscriber.complete (Subscriber.js:122)

at MapSubscriber.Subscriber._complete (Subscriber.js:140)

at MapSubscriber.Subscriber.complete (Subscriber.js:122)

at EmptyObservable._subscribe (EmptyObservable.js:83)

at EmptyObservable.Observable._trySubscribe (Observable.js:172)

at EmptyObservable.Observable.subscribe (Observable.js:160)

at new EmptyError (EmptyError.js:28)

at FirstSubscriber._complete (first.js:154)

at FirstSubscriber.Subscriber.complete (Subscriber.js:122)

at MergeMapSubscriber._complete (mergeMap.js:150)

at MergeMapSubscriber.Subscriber.complete (Subscriber.js:122)

at MapSubscriber.Subscriber._complete (Subscriber.js:140)

at MapSubscriber.Subscriber.complete (Subscriber.js:122)

at EmptyObservable._subscribe (EmptyObservable.js:83)

at EmptyObservable.Observable._trySubscribe (Observable.js:172)

at EmptyObservable.Observable.subscribe (Observable.js:160)

at resolvePromise (zone.js:824)

at resolvePromise (zone.js:795)

at eval (zone.js:873)

at ZoneDelegate.invokeTask (zone.js:425)

at Object.onInvokeTask (core.js:4621)

at ZoneDelegate.invokeTask (zone.js:424)

at Zone.runTask (zone.js:192)

at drainMicroTaskQueue (zone.js:602)

at ZoneTask.invokeTask [as invoke] (zone.js:503)

at invokeTask (zone.js:1540)

回答:

我遇到了与Angular v 4.4.6相同的错误。我发现有两种解决方案可以解决这个错误。一个是将pathMatch: 'full'添加到每个路由定义。另一个是将rxjs降低到v5.5.3以下。如果一个人不适合你,也许另一个人会。

更新:它出现的问题已被固定在rxjs v5.5.5。在使用Angular 5.0.5的项目中,将rxjs升级到v5.5.5后,错误停止发生。

回答:

角最新版本的bug。将pathMatch: 'full'添加到所有路线。

{ 

path: '',

component: HomeComponent,

pathMatch: 'full'

},

{

path: 'about',

component: AboutComponent,

pathMatch: 'full'

},

回答:

我遇到了与Angular 5.0.1和rxjs 5.5.3相同的错误。我们在更改routes数组中的顺序时没有遇到异常。因此,对于你的例子:

const appRoutes: Routes = [ 

{ path: '', redirectTo: '/recipes', pathMatch: 'full'},

{ path: 'recipes/:recipeName', component: RecipesComponent},

{ path: 'recipes', component: RecipesComponent},

];

一般路径(recipes)之前把更详细的路径(recipes/:recipeName)。

以上是 如何调试未被捕获(在promise中):EmptyError:由router.navigate引起的序列中没有元素? 的全部内容, 来源链接: utcz.com/qa/259176.html

回到顶部