Skip to content

Commit

Permalink
fix(history): pass location to subscribe callback (#2736)
Browse files Browse the repository at this point in the history
  • Loading branch information
schiller-manuel authored Nov 11, 2024
1 parent 35ccf89 commit 78fc6d8
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions packages/history/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ export interface NavigateOptions {
export interface RouterHistory {
location: HistoryLocation
length: number
subscribers: Set<() => void>
subscribe: (cb: () => void) => () => void
subscribers: Set<(opts: { location: HistoryLocation }) => void>
subscribe: (cb: (opts: { location: HistoryLocation }) => void) => () => void
push: (path: string, state?: any, navigateOpts?: NavigateOptions) => void
replace: (path: string, state?: any, navigateOpts?: NavigateOptions) => void
go: (index: number, navigateOpts?: NavigateOptions) => void
Expand Down Expand Up @@ -74,12 +74,12 @@ export function createHistory(opts: {
onBlocked?: (onUpdate: () => void) => void
}): RouterHistory {
let location = opts.getLocation()
const subscribers = new Set<() => void>()
const subscribers = new Set<(opts: { location: HistoryLocation }) => void>()
let blockers: Array<BlockerFn> = []

const notify = () => {
location = opts.getLocation()
subscribers.forEach((subscriber) => subscriber())
subscribers.forEach((subscriber) => subscriber({ location }))
}

const tryNavigation = async (
Expand Down Expand Up @@ -108,7 +108,7 @@ export function createHistory(opts: {
return opts.getLength()
},
subscribers,
subscribe: (cb: () => void) => {
subscribe: (cb: (opts: { location: HistoryLocation }) => void) => {
subscribers.add(cb)

return () => {
Expand Down

0 comments on commit 78fc6d8

Please sign in to comment.