router icon indicating copy to clipboard operation
router copied to clipboard

`onStay` property should use current matches, not previous

Open finnan444 opened this issue 1 year ago • 0 comments

Describe the bug

When I change url params on page via navigate like this

const router = useRouter()

const handleButtonClick = (pageNumber: number) => {
  router.navigate({ search: { page: pageNumber }, replace: true })
}

In onStay callback i got page number from params before navigate call

onStay: (match) => {
  console.log('onStay page number', match.search.page)
},

Maybe the problem is here - stayingMatches should filter newMatches instead of previousMatches?

Your Example Website or App

https://github.com/finnan444/tanstack-router-on-stay-error

Steps to Reproduce the Bug or Issue

  1. Go to about page
  2. Click "Go to next page"
  3. Url will be updated, but in console you will see that the page number equals the one in url -1

Expected behavior

I expect the match to be equal to current route search params

Screenshots or Videos

No response

Platform

  • OS: macOS
  • Browser: Chrome
  • Version: 126.0.6478.127

Additional context

No response

finnan444 avatar Jul 05 '24 15:07 finnan444