|
| 1 | +/// <reference lib="dom" /> |
1 | 2 | import React, { ComponentType, useCallback, useEffect, useRef, useState } from 'https://esm.sh/react'
|
2 | 3 | import { DataContext, RouterContext } from './context.ts'
|
3 | 4 | import { E404Page, E501App, E501Page, ErrorBoundary } from './error.ts'
|
@@ -33,7 +34,7 @@ export function ALEPH({ initial }: {
|
33 | 34 | const { url, pageProps } = initial
|
34 | 35 | return { pageProps, url }
|
35 | 36 | })
|
36 |
| - const onpopstate = useCallback(async () => { |
| 37 | + const onpopstate = useCallback(async (e: any) => { |
37 | 38 | const { routing } = ref.current
|
38 | 39 | const { baseUrl } = routing
|
39 | 40 | const [url, pageModuleTree] = routing.createRouter()
|
@@ -70,6 +71,9 @@ export function ALEPH({ initial }: {
|
70 | 71 | return c
|
71 | 72 | }, pageProps)
|
72 | 73 | setPage({ url, pageProps })
|
| 74 | + if (util.isInt(e.scrollTo)) { |
| 75 | + window.scrollTo(e.scrollTo, 0) |
| 76 | + } |
73 | 77 | } else {
|
74 | 78 | setPage({ url, pageProps: null })
|
75 | 79 | }
|
@@ -193,7 +197,7 @@ export async function redirect(url: string, replace?: boolean) {
|
193 | 197 | } else {
|
194 | 198 | history.pushState(null, '', url)
|
195 | 199 | }
|
196 |
| - events.emit('popstate', { type: 'popstate' }) |
| 200 | + events.emit('popstate', { type: 'popstate', scrollTo: 0 }) |
197 | 201 | }
|
198 | 202 |
|
199 | 203 | export function getModuleImportUrl(baseUrl: string, mod: Module, forceFetch = false) {
|
|
0 commit comments