問題タブ [react-router-component]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票する
0 に答える
579 参照

javascript - Failed to execute 'pushState' on 'History'. Function could not be cloned

On the following very basic project:

https://stackblitz.com/edit/react-history-push-with-function-as-arg?file=src%2Fpages%2FPage1.jsx

I have the following code:

My problem is that I need to pass a function to the Page2 through the call to: this.props.history.push({...}). For that I'm using: myFunction inside the state array (which is normally used to send parameters on the transition).

Side note you can skip: in my real scenario will be a function that will take care of cancelling an Axios call, especifically with: axios.canceltoken.source().cancel(). Reference: https://www.pluralsight.com/guides/all-need-to-know-about-axios),

but when transitioning to Page2 I get the following error:

as you can see here:

enter image description here

I know I could save the function on the window object while on Page1 and use it while on Page2 but I think that's not a good practice. As I said above, my end goal is to be able on Page2 to cancel an Axios request I started on Page1.

Is there a way for me to pass that function to Page2?

Thanks in advance!

0 投票する
2 に答える
43 参照

reactjs - React Routerはリンクを変更しますが、本文を変更できません

React router リンクタグは最初のページとページでも変更されましたが、2番目のページには多くのリンクがあります このリンクをクリックすると、リンクは変更できますが、本文は変更できません。どうすれば修正できますか... ルーターコード:

2 ページ目のコード

小道具を介していくつかのデータを渡す

このコードのほんの一部を表示しています... 助けてください...どうすればエラーを修正できますか

完全なコードはこちら: https://gist.github.com/fahadali32/8643d33a2328c1375552e4ba7637fc92