Is it possible to communicate between React Applications?

独自空忆成欢 提交于 2020-02-04 09:04:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!