-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
router location state is broken for imperative nagivation #14815
Comments
I saw that if you set location state from a "new" page (or you do a page refresh before) the destination value is null... If you navigate other routes and then return to the initial page (where you set the location state), the state working properly. |
This broke in #14359, for what it's worth. |
Any luck with this, @sidharthachatterjee? I tried to take a look but those changes are a bit intimidating. Maybe @Moocar would know what's up? |
Hiya! This issue has gone quiet. Spooky quiet. 👻 We get a lot of issues, so we currently close issues after 30 days of inactivity. It’s been at least 20 days since the last update here. If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open! As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contributefor more information about opening PRs, triaging issues, and contributing! Thanks for being a part of the Gatsby community! 💪💜 |
Not stale... |
Having the same issue (in gatsby 2.13.56), I could work around it by using const state =
// eslint-disable-next-line no-restricted-globals
location.state || (typeof history === 'object' && history.state); |
This appears to be fixed in the latest release. . . |
|
Well, this seems to have been resolved somewhere along the way. It's working again in |
Doesn't work in |
Same issue here |
not working in 2.20.24 |
Hey folks - can you confirm that reproduction https://github.com/wKovacs64/gatsby-location-state-test is still relevant? (after updating to latest gatsby?). I will need something to work with to confirm and potentially fix |
I'm unable to reproduce it in Maybe people are experiencing a similar but different issue (?), in which case a fresh reproduction would be needed. |
you're right @wKovacs64. I also ran your test on 2.20.24 and it works fine. going to check what's different on my end and report back... |
Figured it out. My setup includes:
I'm using a pattern similar to this: https://www.gatsbyjs.org/docs/client-only-routes-and-user-authentication. The problem was that the state was being passed to the router, and then rendered in a PrivateRoute component, which in turn failed to pass on down the location props to the component it was itself rendering after the authentication/authorization check. Thanks for the previous tips/help on this thread! |
Had to pass state params via Gatsby Link. Details Page } return (//... ) ` |
Is there any fix for that? On gatsby build it's throwing error WebpackError: TypeError: Cannot read property 'platform' of undefined where Gatsby 2.23.3 |
I think you will find the variable in window.history.state, hope it helps.
Best Regards
Hugens LOUIS
(+509)-47007622
…On Tue, Sep 15, 2020 at 5:02 PM Ziya Fenn ***@***.***> wrote:
Is there any fix for that? On *gatsby build* it's throwing error *WebpackError:
TypeError: Cannot read property 'platform' of undefined* where platform
is location.state.platform,
Tried solution from @vyk1 <https://github.com/vyk1> , didn't help.
Gatsby 2.23.3
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#14815 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABEVNJKEXG5G6KZP6P6FQODSF7I6VANCNFSM4HYQJUHA>
.
|
Description
2019-06-15: Original Problem Statement
Passing state through @reach/router's
navigate
function works in Gatsby v2.8.8 but not in v2.9.0 (nor v2.9.4, the latest version at this time). This broke in #14359.Declarative links pass state correctly (e.g.
<Link to="/page-2" state={{ success: true }}>
).2019-08-23: Update 1
The problem appears partially fixed as of Gatsby v2.13.2 (b8e2adc6, specifically) for development mode (
gatsby develop
) but is still broken in production (gatsby build
output). Also, instead ofnull
,location.state
is nowundefined
.Steps to reproduce
Imperatively navigate to another page. The
location.state
prop will beundefined
in the destination page component.Reproduction:
https://github.com/wKovacs64/gatsby-location-state-test
Expected result
props.location.state
should be populated.Actual result
props.location.state
isundefined
.Environment
The text was updated successfully, but these errors were encountered: