Unverified Commit 5fd16c76 authored by Lee Robinson's avatar Lee Robinson Committed by GitHub

docs: SPAs (#74605)

This documents how to build Single-Page Applications with Next.js.

---------
Co-authored-by: 's avatarDelba de Oliveira <32464864+delbaoliveira@users.noreply.github.com>
Co-authored-by: 's avatarRich Haines <hello@richardhaines.dev>
parent 66059a4a
...@@ -60,20 +60,20 @@ export async function create() {} ...@@ -60,20 +60,20 @@ export async function create() {}
export async function create() {} export async function create() {}
``` ```
```tsx filename="app/ui/button.tsx" switcher ```tsx filename="app/button.tsx" switcher
'use client' 'use client'
import { create } from '@/app/actions' import { create } from './actions'
export function Button() { export function Button() {
return <button onClick={() => create()}>Create</button> return <button onClick={() => create()}>Create</button>
} }
``` ```
```jsx filename="app/ui/button.js" switcher ```jsx filename="app/button.js" switcher
'use client' 'use client'
import { create } from '@/app/actions' import { create } from './actions'
export function Button() { export function Button() {
return <button onClick={() => create()}>Create</button> return <button onClick={() => create()}>Create</button>
......
...@@ -57,7 +57,7 @@ export default function ClientComponentExample() { ...@@ -57,7 +57,7 @@ export default function ClientComponentExample() {
### Skipping SSR ### Skipping SSR
When using `React.lazy()` and Suspense, Client Components will be pre-rendered (SSR) by default. When using `React.lazy()` and Suspense, Client Components will be [prerendered](https://github.com/reactwg/server-components/discussions/4) (SSR) by default.
> **Note:** `ssr: false` option will only work for client components, move it into client components ensure the client code-splitting working properly. > **Note:** `ssr: false` option will only work for client components, move it into client components ensure the client code-splitting working properly.
......
...@@ -35,7 +35,7 @@ const nextConfig = { ...@@ -35,7 +35,7 @@ const nextConfig = {
module.exports = nextConfig module.exports = nextConfig
``` ```
After running `next build`, Next.js will produce an `out` folder which contains the HTML/CSS/JS assets for your application. After running `next build`, Next.js will create an `out` folder with the HTML/CSS/JS assets for your application.
<PagesOnly> <PagesOnly>
......
...@@ -878,6 +878,10 @@ export async function GET(request) {} ...@@ -878,6 +878,10 @@ export async function GET(request) {}
> **Good to know**: If you previously used API routes to call an external API from the client, you can now use [Server Components](/docs/app/building-your-application/rendering/server-components) instead to securely fetch data. Learn more about [data fetching](/docs/app/building-your-application/data-fetching/fetching). > **Good to know**: If you previously used API routes to call an external API from the client, you can now use [Server Components](/docs/app/building-your-application/rendering/server-components) instead to securely fetch data. Learn more about [data fetching](/docs/app/building-your-application/data-fetching/fetching).
#### Single-Page Applications
If you are also migrating to Next.js from a Single-Page Application (SPA) at the same time, see our [documentation](/docs/app/building-your-application/upgrading/single-page-applications) to learn more.
### Step 7: Styling ### Step 7: Styling
In the `pages` directory, global stylesheets are restricted to only `pages/_app.js`. With the `app` directory, this restriction has been lifted. Global styles can be added to any layout, page, or component. In the `pages` directory, global stylesheets are restricted to only `pages/_app.js`. With the `app` directory, this restriction has been lifted. Global styles can be added to any layout, page, or component.
......
--- ---
title: Migrating from Create React App title: Migrating from Create React App
nav_title: Migrating from CRA
description: Learn how to migrate your existing React application from Create React App to Next.js. description: Learn how to migrate your existing React application from Create React App to Next.js.
--- ---
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment