Skip to content

Commit 72b1f7f

Browse files
hussein-m-kandilkirjs
authored andcommitted
docs: fix router event subscription in error handler example
The example incorrectly persisted the error message after a successful navigation retry because the stream only emitted NavigationError events. This update removes the filter and returns an empty string for non-error events, allowing the signal to clear the message on normal navigation.
1 parent 38a354f commit 72b1f7f

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

adev/src/content/guide/routing/data-resolvers.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ You can also handle resolver errors by subscribing to router events and listenin
182182
import { Component, inject, signal } from '@angular/core';
183183
import { Router, NavigationError } from '@angular/router';
184184
import { toSignal } from '@angular/core/rxjs-interop';
185-
import { filter, map } from 'rxjs';
185+
import { map } from 'rxjs';
186186
187187
@Component({
188188
selector: 'app-root',
@@ -202,15 +202,17 @@ export class App {
202202
203203
private navigationErrors = toSignal(
204204
this.router.events.pipe(
205-
filter((event): event is NavigationError => event instanceof NavigationError),
206205
map(event => {
207-
this.lastFailedUrl.set(event.url);
208-
209-
if (event.error) {
210-
console.error('Navigation error', event.error)
206+
if (event instanceof NavigationError) {
207+
this.lastFailedUrl.set(event.url);
208+
209+
if (event.error) {
210+
console.error('Navigation error', event.error)
211+
}
212+
213+
return 'Navigation failed. Please try again.';
211214
}
212-
213-
return 'Navigation failed. Please try again.';
215+
return '';
214216
})
215217
),
216218
{ initialValue: '' }

0 commit comments

Comments
 (0)