Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing state with a Router link no longer works with inferno-router 8.0.3 #1608

Closed
dessalines opened this issue Sep 22, 2022 · 5 comments · Fixed by #1615
Closed

Passing state with a Router link no longer works with inferno-router 8.0.3 #1608

dessalines opened this issue Sep 22, 2022 · 5 comments · Fixed by #1615

Comments

@dessalines
Copy link
Contributor

I also couldn't find any unit tests for state.

Example:

<NavLink
  to={{
    pathname: "/create_post",
    search: "",
    key: "",
    hash: "",
    state: {some: "state here"}
  }}
>a link
</NavLink>

State ends up as null

@Havunen
Copy link
Member

Havunen commented Oct 2, 2022

Hi,

Thanks for reporting the issue.

Where are you expecting this state to be passed? How was it working previously and what version you were using previously?

@dessalines
Copy link
Contributor Author

It used to work on 7.2.1 using:

<NavLink
  to={{
    pathname: "/create_post",
    anyStateHere: XXX,
  }}
/>

...

// Access it like this in the other component:
let anyStateHere = this.props.location.state.anyStateHere; 

@Havunen
Copy link
Member

Havunen commented Oct 3, 2022

Ok thx, I will check

@jhsware
Copy link
Contributor

jhsware commented Nov 6, 2022

NavLink has never supported this, however Link has. This isn't a regression bug, but a missing feature. I have created an issue to investigate what changes have been made to react-router so we can port all of them #1614

@jhsware
Copy link
Contributor

jhsware commented Nov 6, 2022

According to the docs of the package history you should call history.replace(path, [state]) but we do history.replace(to); loosing the state object.

So what happened is that we bumped the history package from v4 to v5 and lost the fallback from v4 where state and location could be passed in a single object:

1. A URL path or
2. A location-like object with { pathname, search, hash, state }

So we need to unpack the object in Link.ts and change our invocation of history.replace and history.push.

Here is a reference to a react-router commit that I believe addresses the same issue. The commit also contains tests.

Havunen pushed a commit that referenced this issue Nov 8, 2022
* Fix regression issue due to update of history package

* Prettier

* Fix linting error

* Added test with actual state object
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

3 participants