Skip to content

Instantly share code, notes, and snippets.

@nathan-lapinski
Created December 2, 2018 11:30
Show Gist options
  • Save nathan-lapinski/e11be380a1b9a2f89d419dd3b42b2941 to your computer and use it in GitHub Desktop.
Save nathan-lapinski/e11be380a1b9a2f89d419dd3b42b2941 to your computer and use it in GitHub Desktop.
excerpt of router.ts demonstrating how switchMap is used to cancel and cleanup pending navigations
private setupNavigations(transitions: Observable<NavigationTransition>): Observable<NavigationTransition> {
return transitions.pipe(
filter(t => t.id !== 0),
// Extract URL
map(t => ({...t, extractedUrl: this.urlHandlingStrategy.extract(t.rawUrl)}) as NavigationTransition),
// Using switchMap so we cancel executing navigations when a new one comes in
switchMap(t => {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment