router icon indicating copy to clipboard operation
router copied to clipboard

Link state missing on navigation

Open msfleischer opened this issue 2 years ago • 1 comments

Describe the bug

The Link/navigate state property doesn't pass the state to the provided route on navigation.

Your Example Website or App

https://stackblitz.com/edit/github-hqyitv?file=src%2Fmain.tsx

Steps to Reproduce the Bug or Issue

Click on the About link in the navbar to navigate to the new route with the state printed out.

Expected behavior

I expected to see the provided state {"test":"value"} to be printed to the screen on the new route. Instead a state with a random ID gets output, e.g. {"id":"16706647803220.5453417445657511"}.

Screenshots or Videos

No response

Platform

  • OS: Linux running in Windows WSL
  • Browser: Chrome
  • Version: 108.0

Additional context

No response

msfleischer avatar Dec 10 '22 09:12 msfleischer

I think this is related to the second part of the issue I desribed in #444, a stackblitz example was included there as well.

vixducis avatar Dec 11 '22 16:12 vixducis

Well, I can confirm this for the latest version.

This is how i navigate:

<tr
      className="border-b bg-white hover:bg-gray-50 dark:border-gray-700 dark:bg-gray-800 dark:hover:bg-gray-600"
      key={id}
      onClick={() => {
        navigate({
          to: "/user/$userId",
          params: {
            userId: String(id),
          },
          state: { user: name, username, email, phone, address },
        }).then(
          () => {},
          () => {}
        );
      }}
    >

And this is the view of who must receive the id and state:

const Profile: FC = () => {
  const { userId } = useParams();
  const router = useRouter();

  const routerState = router.store.currentLocation.state;

  console.log("State", routerState);

  const {
    data,
    error,
    isError,
    isLoading: loadingAlbums,
  } = useQuery<Album[], Error>({
    queryKey: ["user", userId],
    queryFn: () => service.getAlbumByUserId(Number(userId)),
  });

And this is what we get on log:

Screenshot_20230116_174248

Interesting.

SalahAdDin avatar Jan 16 '23 14:01 SalahAdDin

This issue should be fixed. Reopen if you find otherwise.

tannerlinsley avatar Feb 06 '23 05:02 tannerlinsley

I can confirm this is still an issue. State isn't being passed through to commit location.

https://github.com/TanStack/router/blob/83d8bff6009629d1ca4091dcdf602cc1835f7dd1/packages/router/src/router.ts#L799-L806

luke-layerhealth avatar Feb 27 '23 19:02 luke-layerhealth

I can confirm this is still an issue. State isn't being passed through to commit location.

https://github.com/TanStack/router/blob/83d8bff6009629d1ca4091dcdf602cc1835f7dd1/packages/router/src/router.ts#L799-L806

@tannerlinsley Would it be worthy to test?

SalahAdDin avatar Feb 27 '23 22:02 SalahAdDin

Still an issue on latest beta.

maxsalven avatar Jul 19 '23 23:07 maxsalven

Still an issue on latest beta.

it would be nice to open a new PR for fixing it.

SalahAdDin avatar Jul 21 '23 23:07 SalahAdDin