@@ -4,6 +4,9 @@ import { Page } from './types'
4
4
const isServer = typeof window === 'undefined'
5
5
6
6
export class History {
7
+ public static rememberedState = 'rememberedState'
8
+ public static scrollRegions = 'scrollRegions'
9
+
7
10
public static remember ( data : unknown , key : string ) : void {
8
11
History . replaceState ( {
9
12
...currentPage . get ( ) ,
@@ -16,16 +19,16 @@ export class History {
16
19
17
20
public static restore ( key : string ) : unknown {
18
21
if ( ! isServer ) {
19
- return this . getState < { [ key : string ] : any } > ( ' rememberedState' , { } ) ?. [ key ]
22
+ return History . getState < { [ key : string ] : any } > ( History . rememberedState , { } ) ?. [ key ]
20
23
}
21
24
}
22
25
23
26
public static pushState ( page : Page ) : void {
24
- window . history . pushState ( this . pageData ( page ) , '' , page . url )
27
+ window . history . pushState ( History . pageData ( page ) , '' , page . url )
25
28
}
26
29
27
30
public static replaceState ( page : Page ) : void {
28
- window . history . replaceState ( this . pageData ( page ) , '' , page . url )
31
+ window . history . replaceState ( History . pageData ( page ) , '' , page . url )
29
32
}
30
33
31
34
protected static pageData ( page : Page ) : Omit < Page , 'meta' > {
@@ -39,7 +42,7 @@ export class History {
39
42
}
40
43
41
44
public static getState < T > ( key : string , defaultValue ?: T ) : T {
42
- return window . history . state [ key ] ?? defaultValue
45
+ return window . history . state ?. [ key ] ?? defaultValue
43
46
}
44
47
45
48
public static deleteState ( key : string ) {
@@ -49,7 +52,7 @@ export class History {
49
52
}
50
53
51
54
public static hasAnyState ( ) : boolean {
52
- return ! ! this . getAllState ( )
55
+ return ! ! History . getAllState ( )
53
56
}
54
57
55
58
public static getAllState ( ) : any {
0 commit comments