问题
My project is a journey of three react applications, I want to use some data from application 1 to application 2 and application 2 to application 3.
If data to be passed is small, i passed it in query parameter in url of 2nd application.
And if data is large or private, i am planning to send it as a post which will be received by application 2.
Is there any better way of communicating between react applications? Can i make each reach application as a Library which can expose its data to application 2?
回答1:
You could use the postMessage (MDN link), which is now supported in every browser.
It's a cross-domain, event-based messaging system running directly in the browser, with a familiar API.
Be sure to check the message's source before acting on them in your destination page!
回答2:
If you're loading a new page in between then sending to the server via a post is a good idea.
If you're not then you can set it to some global location like window.application1Data = { data: data };
来源:https://stackoverflow.com/questions/40161230/is-it-possible-to-communicate-between-react-applications