简体   繁体   English

React Js Bundle 到另一个网站,如 wordpress 或 php 网站

[英]React Js Bundle to another website like wordpress or php site

I'm beginner and learning using React.js.我是初学者,正在学习使用 React.js。 I want to know if I compile react to bundle.js can it work to Wordpress or another php site?我想知道如果我编译对 bundle.js 的反应,它可以对 Wordpress 或另一个 php 站点起作用吗?

I just need information about it for my current project.我只需要有关我当前项目的信息。 Thanks谢谢

I don't really know what your idea and why you want to do it.我真的不知道你的想法是什么以及你为什么要这样做。

The main problem is in routing.主要问题出在路由上。 Wordpress is CMS with own routing/permalinks system where every created post type has unique url. If you're building SPA with React routing, you cannot use it together with Wordpress. This would work only on separate domains/subdomains (one for Wordpress and one for React.js app) and communicate across Rest API. Wordpress 是具有自己的路由/永久链接系统的 CMS,其中每个创建的帖子类型都有唯一的 url。如果您使用 React 路由构建 SPA,则不能将它与 Wordpress 一起使用。这仅适用于单独的域/子域(一个用于 Wordpress 和一个用于 React.js 应用程序)并通过 Rest API 进行通信。

If your React.js app doesn't have own routing, you can use it with Wordpress. You can easily add specific HTML element to your Wordpress post type (by default it is <div id="root"></div> - you can find where is app binded in your index.js/.tsx file), where will be rendered your React.js app and insert link of bundle script to footer of your Wordpress site.如果你的 React.js 应用程序没有自己的路由,你可以将它与 Wordpress 一起使用。你可以轻松地将特定的 HTML 元素添加到你的 Wordpress 帖子类型(默认情况下它是<div id="root"></div> -你可以在你的 index.js/.tsx 文件中找到应用程序绑定的位置),你的 React.js 应用程序将在哪里呈现,并将捆绑脚本的链接插入到你的 Wordpress 网站的页脚。

So, imagine that your React.js app is something like "same-origin iframe", which you can add to your website.因此,假设您的 React.js 应用程序类似于“同源 iframe”,您可以将其添加到您的网站。

If my answer didn't help you, please add more information.如果我的回答对您没有帮助,请添加更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM