@@ -146,17 +146,17 @@ export class Router {
146146 * the router can then use this to compute how to restore the state back to the previously active
147147 * page.
148148 */
149- private currentPageId : number = 0 ;
149+ private currentPageId = 0 ;
150150 /**
151151 * The ɵrouterPageId of whatever page is currently active in the browser history. This is
152152 * important for computing the target page id for new navigations because we need to ensure each
153153 * page id in the browser history is 1 more than the previous entry.
154154 */
155- private get browserPageId ( ) : number | undefined {
155+ private get browserPageId ( ) : number {
156156 if ( this . canceledNavigationResolution !== 'computed' ) {
157- return undefined ;
157+ return this . currentPageId ;
158158 }
159- return ( this . location . getState ( ) as RestoredState | null ) ?. ɵrouterPageId ;
159+ return ( this . location . getState ( ) as RestoredState | null ) ?. ɵrouterPageId ?? this . currentPageId ;
160160 }
161161 private console = inject ( Console ) ;
162162 private isNgZoneEnabled : boolean = false ;
@@ -332,7 +332,7 @@ export class Router {
332332 this . navigationTransitions . setupNavigations ( this ) . subscribe (
333333 t => {
334334 this . lastSuccessfulId = t . id ;
335- this . currentPageId = this . browserPageId ?? 0 ;
335+ this . currentPageId = this . browserPageId ;
336336 } ,
337337 e => {
338338 this . console . warn ( `Unhandled Navigation Error: ${ e } ` ) ;
@@ -771,7 +771,7 @@ export class Router {
771771 } else {
772772 const state = {
773773 ...transition . extras . state ,
774- ...this . generateNgRouterState ( transition . id , ( this . browserPageId ?? 0 ) + 1 )
774+ ...this . generateNgRouterState ( transition . id , this . browserPageId + 1 )
775775 } ;
776776 this . location . go ( path , '' , state ) ;
777777 }
@@ -784,7 +784,7 @@ export class Router {
784784 */
785785 restoreHistory ( transition : NavigationTransition , restoringFromCaughtError = false ) {
786786 if ( this . canceledNavigationResolution === 'computed' ) {
787- const currentBrowserPageId = this . browserPageId ?? this . currentPageId ;
787+ const currentBrowserPageId = this . browserPageId ;
788788 const targetPagePosition = this . currentPageId - currentBrowserPageId ;
789789 if ( targetPagePosition !== 0 ) {
790790 this . location . historyGo ( targetPagePosition ) ;
@@ -832,7 +832,7 @@ export class Router {
832832 this . generateNgRouterState ( this . lastSuccessfulId , this . currentPageId ) ) ;
833833 }
834834
835- private generateNgRouterState ( navigationId : number , routerPageId ? : number ) {
835+ private generateNgRouterState ( navigationId : number , routerPageId : number ) {
836836 if ( this . canceledNavigationResolution === 'computed' ) {
837837 return { navigationId, ɵrouterPageId : routerPageId } ;
838838 }
0 commit comments