@@ -14,7 +14,8 @@ const waitForNextFrame = () => {
1414}
1515
1616export const getHistoryKey = ( path : string , page ?: number ) => {
17- return page && page > 1 ? `${ path } ?page=${ page } ` : path
17+ const pathname = path . split ( "?" ) [ 0 ]
18+ return page && page > 1 ? `${ pathname } ?page=${ page } ` : pathname
1819}
1920
2021export const recordHistory = ( path : string , page ?: number ) => {
@@ -33,15 +34,8 @@ export const recordHistory = (path: string, page?: number) => {
3334 page : page ?? getGlobalPage ( ) ,
3435 scroll : window . scrollY ,
3536 }
36- console . log ( `record history: [${ key } ]` )
3737 HistoryMap . set ( key , history )
38- }
39-
40- export const recordScroll = ( path : string , page ?: number ) => {
41- const key = getHistoryKey ( path , page )
42- if ( ! HistoryMap . has ( key ) ) return
43- const history = HistoryMap . get ( key ) !
44- history . scroll = window . scrollY
38+ console . log ( `record history: [${ key } ]` )
4539}
4640
4741export const recoverHistory = async ( path : string , page ?: number ) => {
@@ -63,5 +57,21 @@ export const hasHistory = (path: string, page?: number) => {
6357
6458export const clearHistory = ( path : string , page ?: number ) => {
6559 const key = getHistoryKey ( path , page )
66- HistoryMap . delete ( key )
60+ if ( hasHistory ( path , page ) ) {
61+ HistoryMap . delete ( key )
62+ console . log ( `clear history: [${ key } ]` )
63+ }
6764}
65+
66+ document . addEventListener (
67+ "click" ,
68+ ( e ) => {
69+ let target = e . target as HTMLElement
70+ let link = target . closest ( "a" )
71+ let path = link ?. getAttribute ( "href" )
72+ if ( path ) {
73+ clearHistory ( decodeURIComponent ( path ) )
74+ }
75+ } ,
76+ true ,
77+ )
0 commit comments