I'm trying to implement a simple angular route
const appRoutes: Routes = [
{ path: '' ,redirectTo: '/recipes', pathMatch: 'full'},
{ path: 'recipes' , component: RecipesComponent},
{ path: 'recipes/:recipeName' , component: RecipesComponent},
];
in some component that generates the list, i have a function that on click of a updates state variable and routes, though I also have fetching mechanism subscriber happening on initialization.
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]);
}
But when I try to click on a link that reroutes to component with parameter I get the following:
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)
I encountered the same error with Angular v 4.4.6. There were two alternative solutions I found to resolve the error. One was adding pathMatch: 'full'
to every route definition. The other was downgrading rxjs below v5.5.3. If one does not work for you perhaps the other will.
update: it appears the problem has been fixed in rxjs v5.5.5. In a project using Angular 5.0.5, after upgrading rxjs to v5.5.5 the error stopped happening.
Angular latest version bug. Add pathMatch: 'full'
to all routes.
{
path: '',
component: HomeComponent,
pathMatch: 'full'
},
{
path: 'about',
component: AboutComponent,
pathMatch: 'full'
},
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With