@@ -14,6 +14,7 @@ export class Router {
14
14
protected resolveComponent ! : PageResolver
15
15
protected swapComponent ! : PageHandler
16
16
protected visitOptions ! : VisitOptions
17
+ protected navigationType ?: string
17
18
protected activeVisit ?: ActiveVisit
18
19
protected visitId : VisitId = null
19
20
@@ -33,6 +34,9 @@ export class Router {
33
34
this . swapComponent = swapComponent
34
35
this . visitOptions = visitOptions
35
36
37
+ this . setNavigationType ( )
38
+ this . clearRememberedStateOnReload ( )
39
+
36
40
if ( this . isBackForwardVisit ( ) ) {
37
41
this . handleBackForwardVisit ( this . page )
38
42
} else if ( this . isLocationVisit ( ) ) {
@@ -44,6 +48,18 @@ export class Router {
44
48
this . setupEventListeners ( )
45
49
}
46
50
51
+ protected setNavigationType ( ) : void {
52
+ this . navigationType = ( window . performance && window . performance . getEntriesByType ( 'navigation' ) . length > 0 )
53
+ ? ( window . performance . getEntriesByType ( 'navigation' ) [ 0 ] as PerformanceNavigationTiming ) . type
54
+ : 'navigate'
55
+ }
56
+
57
+ protected clearRememberedStateOnReload ( ) : void {
58
+ if ( this . navigationType === 'reload' && window . history . state ?. rememberedState ) {
59
+ delete window . history . state . rememberedState
60
+ }
61
+ }
62
+
47
63
protected handleInitialPageVisit ( page : Page ) : void {
48
64
this . page . url += window . location . hash
49
65
this . setPage ( page , { preserveState : true } ) . then ( ( ) => fireNavigateEvent ( page ) )
@@ -109,10 +125,7 @@ export class Router {
109
125
}
110
126
111
127
protected isBackForwardVisit ( ) : boolean {
112
- return window . history . state
113
- && window . performance
114
- && window . performance . getEntriesByType ( 'navigation' ) . length > 0
115
- && ( window . performance . getEntriesByType ( 'navigation' ) [ 0 ] as PerformanceNavigationTiming ) . type === 'back_forward'
128
+ return window . history . state && this . navigationType === 'back_forward'
116
129
}
117
130
118
131
protected handleBackForwardVisit ( page : Page ) : void {
0 commit comments