使用 Spring Boot 的服务器端渲染 React [英] Server Side Rendering React Using Spring Boot

查看:130
本文介绍了使用 Spring Boot 的服务器端渲染 React的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查看使用 Spring Boot 和 React 的以下教程.https://spring.io/guides/tutorials/react-and-spring-data-rest/

I was looking over the following tutorial using Spring Boot and React. https://spring.io/guides/tutorials/react-and-spring-data-rest/

React 是否会在服务器端渲染,因为它被渲染到 Thymeleaf 模板中?对于上下文,我已经放置了下面教程中的 Thymeleaf 模板和 React 文件代码.

Would the React be server-side rendered here, since it is being rendered into the Thymeleaf template? For context I have placed the Thymeleaf template and React file code from the tutorial below.

src/main/resources/templates/index.html

src/main/resources/templates/index.html

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head lang="en">
    <meta charset="UTF-8"/>
    <title>ReactJS + Spring Data REST</title>
    <link rel="stylesheet" href="/main.css" />
</head>

<body>

    <div id="react"></div>

    <script src="built/bundle.js"></script>

</body>
</html>

src/main/js/app.js - 渲染代码

src/main/js/app.js - rendering code

ReactDOM.render(
    <App />,
    document.getElementById('react')
)

推荐答案

在给定的示例中,React 没有在服务器端呈现.Thymeleaf HTML 按原样输出.如教程所示,通过调用 Spring Boot 后端中的服务设置在客户端获取数据.

In the given example React is not rendered server-side. The Thymeleaf HTML is outputted as is. Data is fetched client-side by calling services setup in the Spring Boot backend as shown in the tutorial.

这篇关于使用 Spring Boot 的服务器端渲染 React的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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