简体   繁体   English

如何将 Next.js 应用于使用 create-react-app 创建的 React 项目?

[英]How can I apply Next.js to a React project created with create-react-app?

I'd tried to figure out how to use server side rendering (SSR) on my existing react, and I found Next.js which is a SSR framework for React.我试图弄清楚如何在我现有的 React 上使用服务器端渲染 (SSR),我发现 Next.js 是 React 的 SSR 框架。

Also, there is create-next-app to easily create Next.js app like CRA.此外,还有create-next-app可以轻松创建 Next.js 应用程序,如 CRA。 As I already have my existing React project, I need to make it compatible with Next.js.由于我已经拥有现有的 React 项目,因此我需要使其与 Next.js 兼容。 But, they have quite different project architecutre.但是,他们有完全不同的项目架构。

I attached two architectures of create-next-app and create-react-app each with images below.我附上了create-next-appcreate-react-app两个架构,每个架构都带有下面的图片。 As Next requires the folder pages , I feel like I need to move my components in that folder, but I'm confused about src and public folder in create-react-app .由于 Next 需要文件夹pages ,我觉得我需要在该文件夹中移动我的组件,但我对create-react-app srcpublic文件夹感到困惑。

Can anyone help me how can I apply Next.js to an existing React app?任何人都可以帮助我如何将 Next.js 应用于现有的 React 应用程序?

create-next-app创建下一个应用程序

在此处输入图片说明

create-react-app创建反应应用程序

在此处输入图片说明

You can install Next js by adding 'next' package to your CRA.您可以通过将“next”包添加到 CRA 来安装 Next js。 However, you would have to refractor part of your codebase.但是,您必须折射部分代码库。 The src folder should contain a subfolder called 'pages', consisting of your paths. src 文件夹应包含一个名为“pages”的子文件夹,其中包含您的路径。

Visit the Next JS Documentation for more访问Next JS 文档了解更多信息

暂无
暂无

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

相关问题 如何将使用 create-react-app 构建的 React 项目升级到下一个 create-react-app 版本? - How to upgrade a React project built with create-react-app to the next create-react-app version? 如何在codepen中运行使用“create-react-app”创建的react项目? - how to run react project created with "create-react-app" in codepen? 如何在使用create-react-app创建的文件中导入Emscripten生成的.wasm / js文件 - How can I import Emscripten generated .wasm/js files in files created with create-react-app 如何编写在项目创建的 create-react-app 的单页反应路由器上工作的 JS - How to write JS which working on single page of react router at project created create-react-app 从 create-react-app (CRA) 转换为 CRA + Next.Js 应用 - Conversion from an create-react-app (CRA) to CRA + Next.Js app 如何将Redux添加到使用Create-React-App创建的React项目中? - How should I add Redux to a React project created with Create-React-App? react-i18next 未在使用 create-react-app 创建的 React 应用程序中加载 json 翻译文件 - react-i18next not loading json translation files in React app created with create-react-app 从Create-React-App升级到Next.js - CSS样式表不起作用 - Upgrading From Create-React-App to Next.js - CSS stylesheets are not working 如何删除 React App 符号和名称或“使用 create-react-app 创建的网站”? - How can I remove the React App symbol and name or the “Website created using create-react-app”? 如何使用create-react-app创建一个新项目 - how do I create a new project with create-react-app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM