如何使用drupal自定义模块将React应用程序集成到drupal 8中? [英] How to integrate a react application in drupal 8, using drupal custom module?

查看:121
本文介绍了如何使用drupal自定义模块将React应用程序集成到drupal 8中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对React和Drupal 8很陌生。我知道要在Drupal和React SPA中创建自定义模块,但是我无法使用drupal8控制器调用react应用。
有人可以让我弄清楚在drupal 8中集成react app的流程和正确方法吗?

I am very new to react and drupal 8. I know to create custom modules in drupal and react SPAs, but I m not able to call my react app using a drupal8 controller . Can someone please make me clear of the flow and the correct way to integrate react app in drupal 8?

推荐答案

因此,实际上没有很好的方法从常规Drupal控制器层或树枝中调用React应用程序Drupal 8的模板。

So there isn't really a good means of calling a React application from within the regular Drupal controller layer or in the twig templates of Drupal 8.

人们通常有两种方式将React Application连接到D8。

There are two ways people usually connect a React Application to D8.

选项1-逐步分离的站点-这是Drupal仍使用TWIG引擎生成绝大多数站点视图的地方,并且可以在其中的一小部分使用React通过基于Drupal的Web服务与Drupal通信时访问该站点。查看此项目以获取更多信息- https://www.drupal.org/project/pdb。如果您只是想添加一个基于React的小窗口小部件,但又想保留标准TWIG,那么这是一个不错的选择。

Option 1 - Progressively decoupled sites - This is where Drupal still uses the TWIG engine to generate the vast majority of the site views, and can use React for some small part of the site while communicating with Drupal through a Drupal based webservice. Check out this project for more information - https://www.drupal.org/project/pdb. This is a nice option if you just want to add a small React based widget, but want to keep the bulk of your site in using standard TWIG.

选项2-完全解耦站点-在这里,您可以使用React渲染100%的应用程序视图层,而仅将Drupal用作提供Web服务的CMS。 Web服务部分有多个选项,包括 https://www.drupal.org/project/graphql https ://www.drupal.org/docs/8/api/restful-web-services-api/restful-web-services-api-overview 。因此,一个示例是在静态服务器上提供一个create-react-app并通过Web服务与D8进行通信。

Option 2 - Fully decouples sites - This is where you render 100% of your applications view layer using React, and just use Drupal as a CMS that provides a web service. There are multiple options for the webservice portion including https://www.drupal.org/project/graphql and https://www.drupal.org/docs/8/api/restful-web-services-api/restful-web-services-api-overview. So an example of this would be serving a create-react-app on a static server and communication with D8 through a web service.

以下是一些其他信息,可能会有所帮助指导您的决定。
https://dri.es/how-to-decouple- drupal-in-2018

Here is some additional information that might help guide your decision. https://dri.es/how-to-decouple-drupal-in-2018

祝你好运!

这篇关于如何使用drupal自定义模块将React应用程序集成到drupal 8中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆