1+ import { Location as NgLocation } from '@angular/common' ;
12import {
23 APP_INITIALIZER ,
34 FactoryProvider ,
@@ -14,7 +15,7 @@ import {
1415 Router ,
1516} from '@angular/router' ;
1617import { ComponentStore , provideComponentStore } from '@ngrx/component-store' ;
17- import { filter , map , Observable , switchMap , take } from 'rxjs' ;
18+ import { filter , map , Observable , pipe , switchMap , take , tap } from 'rxjs' ;
1819import { filterRouterEvents } from '../filter-router-event.operator' ;
1920import { isPopstateNavigationStart } from './popstate-navigation-start' ;
2021import {
@@ -57,6 +58,7 @@ export function provideRouterHistoryStore(): Provider[] {
5758
5859@Injectable ( )
5960export class RouterHistoryStore extends ComponentStore < RouterHistoryState > {
61+ #location = inject ( NgLocation ) ;
6062 #router = inject ( Router ) ;
6163
6264 /**
@@ -163,6 +165,24 @@ export class RouterHistoryStore extends ComponentStore<RouterHistoryState> {
163165 this . #addRouterNavigatedSequence( this . #routerNavigated$) ;
164166 }
165167
168+ /**
169+ * Navigate back in the browser history.
170+ *
171+ * @remarks
172+ * This is only available when the browser history contains a back entry.
173+ */
174+ onNavigateBack = this . effect < void > ( pipe ( tap ( ( ) => this . #location. back ( ) ) ) ) ;
175+
176+ /**
177+ * Navigate forward in the browser history.
178+ *
179+ * @remarks
180+ * This is only available when the browser history contains a forward entry.
181+ */
182+ onNavigateForward = this . effect < void > (
183+ pipe ( tap ( ( ) => this . #location. forward ( ) ) )
184+ ) ;
185+
166186 /**
167187 * Add a router navigated sequence to the router navigated history.
168188 */
0 commit comments