Skip to content

onStay property should use current matches, not previous #1901

@finnan444

Description

@finnan444

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions