Skip to content

Commit

Permalink
Merge pull request #430 from kitbagjs/fix-route-props-clearing
Browse files Browse the repository at this point in the history
  • Loading branch information
pleek91 authored Jan 18, 2025
2 parents e5ebc4d + 75dd2e6 commit 036324c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
30 changes: 30 additions & 0 deletions src/routeProps.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { expect, test, vi } from 'vitest'
import { createRoute } from './services/createRoute'
import { createRouter } from './services/createRouter'

test('props are called each time the route is matched', async () => {
const props = vi.fn()

const route = createRoute({
name: 'test',
path: '/[param]',
}, props)

const router = createRouter([route], {
initialUrl: '/',
})

await router.start()

await router.push('test', { param: 'foo' })

expect(props).toHaveBeenCalledTimes(1)

await router.push('test', { param: 'bar' })

expect(props).toHaveBeenCalledTimes(2)

await router.push('test', { param: 'foo' })

expect(props).toHaveBeenCalledTimes(3)
})
2 changes: 1 addition & 1 deletion src/services/createPropStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export function createPropStore(): PropStore {
}

function clearUnusedStoreEntries(keysToKeep: string[]): void {
for (const key in store.keys()) {
for (const key of store.keys()) {
if (keysToKeep.includes(key)) {
continue
}
Expand Down

0 comments on commit 036324c

Please sign in to comment.