Skip to content

Commit

Permalink
feat: add navigation effects
Browse files Browse the repository at this point in the history
  • Loading branch information
LayZeeDK committed Jan 5, 2023
1 parent 4d5d839 commit 9e2d8aa
Showing 1 changed file with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Location as NgLocation } from '@angular/common';
import {
APP_INITIALIZER,
FactoryProvider,
Expand All @@ -14,7 +15,7 @@ import {
Router,
} from '@angular/router';
import { ComponentStore, provideComponentStore } from '@ngrx/component-store';
import { filter, map, Observable, switchMap, take } from 'rxjs';
import { filter, map, Observable, pipe, switchMap, take, tap } from 'rxjs';
import { filterRouterEvents } from '../filter-router-event.operator';
import { isPopstateNavigationStart } from './popstate-navigation-start';
import {
Expand Down Expand Up @@ -57,6 +58,7 @@ export function provideRouterHistoryStore(): Provider[] {

@Injectable()
export class RouterHistoryStore extends ComponentStore<RouterHistoryState> {
#location = inject(NgLocation);
#router = inject(Router);

/**
Expand Down Expand Up @@ -163,6 +165,24 @@ export class RouterHistoryStore extends ComponentStore<RouterHistoryState> {
this.#addRouterNavigatedSequence(this.#routerNavigated$);
}

/**
* Navigate back in the browser history.
*
* @remarks
* This is only available when the browser history contains a back entry.
*/
onNavigateBack = this.effect<void>(pipe(tap(() => this.#location.back())));

/**
* Navigate forward in the browser history.
*
* @remarks
* This is only available when the browser history contains a forward entry.
*/
onNavigateForward = this.effect<void>(
pipe(tap(() => this.#location.forward()))
);

/**
* Add a router navigated sequence to the router navigated history.
*/
Expand Down

0 comments on commit 9e2d8aa

Please sign in to comment.