Skip to content

Commit

Permalink
page store だけだと hashchange を拾えなかったので、拾うようなロジックを追加
Browse files Browse the repository at this point in the history
これが関係ある?(ちゃんと読んでない)
sveltejs/kit#4554
  • Loading branch information
kazuma1989 committed Feb 28, 2023
1 parent 95d9a2a commit cfe9923
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/lib/observeRoute.ts
@@ -1,7 +1,7 @@
import { browser } from "$app/environment"
import { goto } from "$app/navigation"
import { page } from "$app/stores"
import { distinctUntilChanged, map, Observable } from "rxjs"
import { distinctUntilChanged, fromEvent, map, merge, Observable } from "rxjs"
import { fromRoute, toRoute, type Route } from "./toRoute"
import { shareRecent } from "./util/shareRecent"

Expand All @@ -17,12 +17,20 @@ export function replaceRoute(route: Route): void {
}

function observeHash(): Observable<`#${string}`> {
return new Observable<URL>((sub) =>
page.subscribe((_) => {
sub.next(_.url)
})
return merge(
new Observable<string>((sub) =>
page.subscribe((_) => {
sub.next(_.url.hash)
})
),
window
? fromEvent<WindowEventMap["hashchange"]>(
window,
"hashchange" satisfies keyof WindowEventMap
).pipe(map(() => window.location.hash))
: []
).pipe(
map((_) => (_.hash || "#") as `#${string}`),
map((_) => (_ || "#") as `#${string}`),
distinctUntilChanged(),
shareRecent()
)
Expand Down

0 comments on commit cfe9923

Please sign in to comment.