Question? bug?
recently I migration history V1.13.0 to V4.7.2 , i got an error when i use history.push .
more detail see below :
reason: some param in the state is a method
code: history.push('/abc',{callback: () => {// done something});
error:
Uncaught DOMException: Failed to execute 'pushState' on 'History': function (data) {
// done something } could not be cloned.
this problem never found in V1.13.0
there are other ways to solve this problem?
thanks advance
@keith890303 Did you manage to fix this? I'm having the same issue.
It looks like history v1.3.0 used sessionStorage, which apparently will serialize a function. However, from what I can tell, you would have had to parse the function yourself in order to run it. I guess I am a bit confused on _why_ you would want to store a function. Why not just store any arguments in state and call the function?
I've already resolved my issue. In my case this was the problem: https://stackoverflow.com/questions/24425885/failed-to-execute-pushstate-on-history-error-when-using-window-history-pushs
Any solution for functions in state? I'm having this problem for any function that I pass as state
I got this error when trying to add state (object) which contained something it didn't like. The data actually represented a caught error so in certain cases it worked and others it wasn't serializable (or whatever is needed).
I solved it using https://www.npmjs.com/package/safe-json-stringify which can serialize something even if it has functions or circular references. For error handling this was exactly what I wanted - a guarantee that the caught string could be serialized as best as possible.
Most helpful comment
I've already resolved my issue. In my case this was the problem: https://stackoverflow.com/questions/24425885/failed-to-execute-pushstate-on-history-error-when-using-window-history-pushs