1
+ import { Location as NgLocation } from '@angular/common' ;
1
2
import {
2
3
APP_INITIALIZER ,
3
4
FactoryProvider ,
@@ -14,7 +15,7 @@ import {
14
15
Router ,
15
16
} from '@angular/router' ;
16
17
import { 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' ;
18
19
import { filterRouterEvents } from '../filter-router-event.operator' ;
19
20
import { isPopstateNavigationStart } from './popstate-navigation-start' ;
20
21
import {
@@ -57,6 +58,7 @@ export function provideRouterHistoryStore(): Provider[] {
57
58
58
59
@Injectable ( )
59
60
export class RouterHistoryStore extends ComponentStore < RouterHistoryState > {
61
+ #location = inject ( NgLocation ) ;
60
62
#router = inject ( Router ) ;
61
63
62
64
/**
@@ -163,6 +165,24 @@ export class RouterHistoryStore extends ComponentStore<RouterHistoryState> {
163
165
this . #addRouterNavigatedSequence( this . #routerNavigated$) ;
164
166
}
165
167
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
+
166
186
/**
167
187
* Add a router navigated sequence to the router navigated history.
168
188
*/
0 commit comments