I don't know if this is done by principal or if you could add this as a feature.
We're attempting to remove IDs from our API and in the URL. So now I'm attempting to pass the self link create by HATEOS in a JSON object.
I would like to pass the data via the pushState state parameter.
onClickEditButton(selfLinkObject) {
this.history.pushState(selfLinkObject, "/my/url");
}
But when I attempt to get the state it's not being passed.
import React from "react"
import { History } from "react-router"
export default React.createClass({
mixins: [History],
componentDidMount() {
console.log(this.state);
console.log(this.history.state);
console.log(history.state);
},
render() {
<p>Check the console to see if the state is passed from the pushState(state, url, params);</p>
}
});
Am I making sense or am I a complete idiot? Cause me being a complete idiot is very possible.
Thanks for your question!
We want to make sure that the GitHub issue tracker remains the best place to track bug reports and feature requests that affect the development of React Router.
Questions like yours deserve a purpose-built Q&A forum. Would you like to post this question to Stack Overflow with the tag #react-router? https://stackoverflow.com/questions/ask?tags=react-router.
We also have an active and helpful React Router community on Reactiflux, which is a great place to get fast help with React Router and with the rest of the React ecosystem. You can join at https://discord.gg/0ZcbPKXt5bYaNQ46.
@taion Thanks for your reply. I am actually creating a feature request to support passing state data in
history.pushState(state, url, param)
I understand that this might need to be a feature request in history (createBrowserHistory)
For reference here's the Stack Overflow page http://stackoverflow.com/questions/34169068/passing-state-via-this-history-pushstate
That feature exists. It's your code that has problems.
Thanks @taion FWIW I'm stupid. You're smart. I was wrong. You were right. You're the best. I'm the worst. You're very good-looking. I'm not attractive.
The state is on location so, you can access it via this.props.location.state
THANK YOU!
That's a bit... much. When I said "ask on Discord or Stack Overflow", that's because I think those are actually better places to get help on these sorts of things. We want our users to be able to successfully use React Router, but we just believe that those sorts of problems aren't well addressed via our issues.
Most helpful comment
Thanks @taion FWIW I'm stupid. You're smart. I was wrong. You were right. You're the best. I'm the worst. You're very good-looking. I'm not attractive.
The state is on
locationso, you can access it viathis.props.location.stateTHANK YOU!