{ // 获取包含Hugging Face文本的span元素 const spans = link.querySelectorAll('span.whitespace-nowrap, span.hidden.whitespace-nowrap'); spans.forEach(span => { if (span.textContent && span.textContent.trim().match(/Hugging\s*Face/i)) { span.textContent = 'AI快站'; } }); }); // 替换logo图片的alt属性 document.querySelectorAll('img[alt*="Hugging"], img[alt*="Face"]').forEach(img => { if (img.alt.match(/Hugging\s*Face/i)) { img.alt = 'AI快站 logo'; } }); } // 替换导航栏中的链接 function replaceNavigationLinks() { // 已替换标记,防止重复运行 if (window._navLinksReplaced) { return; } // 已经替换过的链接集合,防止重复替换 const replacedLinks = new Set(); // 只在导航栏区域查找和替换链接 const headerArea = document.querySelector('header') || document.querySelector('nav'); if (!headerArea) { return; } // 在导航区域内查找链接 const navLinks = headerArea.querySelectorAll('a'); navLinks.forEach(link => { // 如果已经替换过,跳过 if (replacedLinks.has(link)) return; const linkText = link.textContent.trim(); const linkHref = link.getAttribute('href') || ''; // 替换Spaces链接 - 仅替换一次 if ( (linkHref.includes('/spaces') || linkHref === '/spaces' || linkText === 'Spaces' || linkText.match(/^s*Spacess*$/i)) && linkText !== 'OCR模型免费转Markdown' && linkText !== 'OCR模型免费转Markdown' ) { link.textContent = 'OCR模型免费转Markdown'; link.href = 'https://fast360.xyz'; link.setAttribute('target', '_blank'); link.setAttribute('rel', 'noopener noreferrer'); replacedLinks.add(link); } // 删除Posts链接 else if ( (linkHref.includes('/posts') || linkHref === '/posts' || linkText === 'Posts' || linkText.match(/^s*Postss*$/i)) ) { if (link.parentNode) { link.parentNode.removeChild(link); } replacedLinks.add(link); } // 替换Docs链接 - 仅替换一次 else if ( (linkHref.includes('/docs') || linkHref === '/docs' || linkText === 'Docs' || linkText.match(/^s*Docss*$/i)) && linkText !== '模型下载攻略' ) { link.textContent = '模型下载攻略'; link.href = '/'; replacedLinks.add(link); } // 删除Enterprise链接 else if ( (linkHref.includes('/enterprise') || linkHref === '/enterprise' || linkText === 'Enterprise' || linkText.match(/^s*Enterprises*$/i)) ) { if (link.parentNode) { link.parentNode.removeChild(link); } replacedLinks.add(link); } }); // 查找可能嵌套的Spaces和Posts文本 const textNodes = []; function findTextNodes(element) { if (element.nodeType === Node.TEXT_NODE) { const text = element.textContent.trim(); if (text === 'Spaces' || text === 'Posts' || text === 'Enterprise') { textNodes.push(element); } } else { for (const child of element.childNodes) { findTextNodes(child); } } } // 只在导航区域内查找文本节点 findTextNodes(headerArea); // 替换找到的文本节点 textNodes.forEach(node => { const text = node.textContent.trim(); if (text === 'Spaces') { node.textContent = node.textContent.replace(/Spaces/g, 'OCR模型免费转Markdown'); } else if (text === 'Posts') { // 删除Posts文本节点 if (node.parentNode) { node.parentNode.removeChild(node); } } else if (text === 'Enterprise') { // 删除Enterprise文本节点 if (node.parentNode) { node.parentNode.removeChild(node); } } }); // 标记已替换完成 window._navLinksReplaced = true; } // 替换代码区域中的域名 function replaceCodeDomains() { // 特别处理span.hljs-string和span.njs-string元素 document.querySelectorAll('span.hljs-string, span.njs-string, span[class*="hljs-string"], span[class*="njs-string"]').forEach(span => { if (span.textContent && span.textContent.includes('huggingface.co')) { span.textContent = span.textContent.replace(/huggingface.co/g, 'aifasthub.com'); } }); // 替换hljs-string类的span中的域名(移除多余的转义符号) document.querySelectorAll('span.hljs-string, span[class*="hljs-string"]').forEach(span => { if (span.textContent && span.textContent.includes('huggingface.co')) { span.textContent = span.textContent.replace(/huggingface.co/g, 'aifasthub.com'); } }); // 替换pre和code标签中包含git clone命令的域名 document.querySelectorAll('pre, code').forEach(element => { if (element.textContent && element.textContent.includes('git clone')) { const text = element.innerHTML; if (text.includes('huggingface.co')) { element.innerHTML = text.replace(/huggingface.co/g, 'aifasthub.com'); } } }); // 处理特定的命令行示例 document.querySelectorAll('pre, code').forEach(element => { const text = element.innerHTML; if (text.includes('huggingface.co')) { // 针对git clone命令的专门处理 if (text.includes('git clone') || text.includes('GIT_LFS_SKIP_SMUDGE=1')) { element.innerHTML = text.replace(/huggingface.co/g, 'aifasthub.com'); } } }); // 特别处理模型下载页面上的代码片段 document.querySelectorAll('.flex.border-t, .svelte_hydrator, .inline-block').forEach(container => { const content = container.innerHTML; if (content && content.includes('huggingface.co')) { container.innerHTML = content.replace(/huggingface.co/g, 'aifasthub.com'); } }); // 特别处理模型仓库克隆对话框中的代码片段 try { // 查找包含"Clone this model repository"标题的对话框 const cloneDialog = document.querySelector('.svelte_hydration_boundary, [data-target="MainHeader"]'); if (cloneDialog) { // 查找对话框中所有的代码片段和命令示例 const codeElements = cloneDialog.querySelectorAll('pre, code, span'); codeElements.forEach(element => { if (element.textContent && element.textContent.includes('huggingface.co')) { if (element.innerHTML.includes('huggingface.co')) { element.innerHTML = element.innerHTML.replace(/huggingface.co/g, 'aifasthub.com'); } else { element.textContent = element.textContent.replace(/huggingface.co/g, 'aifasthub.com'); } } }); } // 更精确地定位克隆命令中的域名 document.querySelectorAll('[data-target]').forEach(container => { const codeBlocks = container.querySelectorAll('pre, code, span.hljs-string'); codeBlocks.forEach(block => { if (block.textContent && block.textContent.includes('huggingface.co')) { if (block.innerHTML.includes('huggingface.co')) { block.innerHTML = block.innerHTML.replace(/huggingface.co/g, 'aifasthub.com'); } else { block.textContent = block.textContent.replace(/huggingface.co/g, 'aifasthub.com'); } } }); }); } catch (e) { // 错误处理但不打印日志 } } // 当DOM加载完成后执行替换 if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', () => { replaceHeaderBranding(); replaceNavigationLinks(); replaceCodeDomains(); // 只在必要时执行替换 - 3秒后再次检查 setTimeout(() => { if (!window._navLinksReplaced) { console.log('[Client] 3秒后重新检查导航链接'); replaceNavigationLinks(); } }, 3000); }); } else { replaceHeaderBranding(); replaceNavigationLinks(); replaceCodeDomains(); // 只在必要时执行替换 - 3秒后再次检查 setTimeout(() => { if (!window._navLinksReplaced) { console.log('[Client] 3秒后重新检查导航链接'); replaceNavigationLinks(); } }, 3000); } // 增加一个MutationObserver来处理可能的动态元素加载 const observer = new MutationObserver(mutations => { // 检查是否导航区域有变化 const hasNavChanges = mutations.some(mutation => { // 检查是否存在header或nav元素变化 return Array.from(mutation.addedNodes).some(node => { if (node.nodeType === Node.ELEMENT_NODE) { // 检查是否是导航元素或其子元素 if (node.tagName === 'HEADER' || node.tagName === 'NAV' || node.querySelector('header, nav')) { return true; } // 检查是否在导航元素内部 let parent = node.parentElement; while (parent) { if (parent.tagName === 'HEADER' || parent.tagName === 'NAV') { return true; } parent = parent.parentElement; } } return false; }); }); // 只在导航区域有变化时执行替换 if (hasNavChanges) { // 重置替换状态,允许再次替换 window._navLinksReplaced = false; replaceHeaderBranding(); replaceNavigationLinks(); } }); // 开始观察document.body的变化,包括子节点 if (document.body) { observer.observe(document.body, { childList: true, subtree: true }); } else { document.addEventListener('DOMContentLoaded', () => { observer.observe(document.body, { childList: true, subtree: true }); }); } })(); \n \n )\n }\n\n* The `app` directory **must** include a root layout.\n* The root layout must define ``, and `` tags since Next.js does not automatically create them\n* The root layout replaces the `pages/_app.tsx` and `pages/_document.tsx` files.\n* `.js`, `.jsx`, or `.tsx` extensions can be used for layout files.\n\nTo manage `` HTML elements, you can use the [built-in SEO support](/docs/app/building-your-application/optimizing/metadata):\n\napp/layout.tsx\n\nTypeScript\n\nJavaScriptTypeScript\n\n import { Metadata } from 'next'\n \n export const metadata: Metadata = {\n title: 'Home',\n description: 'Welcome to Next.js',\n }\n\n#### [Migrating `_document.js` and `_app.js`](#migrating-_documentjs-and-_appjs)\n\nIf you have an existing `_app` or `_document` file, you can copy the contents (e.g. global styles) to the root layout (`app/layout.tsx`). Styles in `app/layout.tsx` will _not_ apply to `pages/*`. You should keep `_app`/`_document` while migrating to prevent your `pages/*` routes from breaking. Once fully migrated, you can then safely delete them.\n\nIf you are using any React Context providers, they will need to be moved to a [Client Component](/docs/app/building-your-application/rendering/client-components).\n\n#### [Migrating the `getLayout()` pattern to Layouts (Optional)](#migrating-the-getlayout-pattern-to-layouts-optional)\n\nNext.js recommended adding a [property to Page components](/docs/pages/building-your-application/routing/pages-and-layouts#layout-pattern#per-page-layouts) to achieve per-page layouts in the `pages` directory. This pattern can be replaced with native support for [nested layouts](/docs/app/building-your-application/routing/pages-and-layouts#layouts) in the `app` directory.\n\nSee before and after example\n\n**Before**\n\ncomponents/DashboardLayout.js\n\n export default function DashboardLayout({ children }) {\n return (\n
\n

My Dashboard

\n {children}\n
\n )\n }\n\npages/dashboard/index.js\n\n import DashboardLayout from '../components/DashboardLayout'\n \n export default function Page() {\n return

My Page

\n }\n \n Page.getLayout = function getLayout(page) {\n return {page}\n }\n\n**After**\n\n* Remove the `Page.getLayout` property from `pages/dashboard/index.js` and follow the [steps for migrating pages](#step-4-migrating-pages) to the `app` directory.\n \n app/dashboard/page.js\n \n export default function Page() {\n return

My Page

\n }\n \n* Move the contents of `DashboardLayout` into a new [Client Component](/docs/app/building-your-application/rendering/client-components) to retain `pages` directory behavior.\n \n app/dashboard/DashboardLayout.js\n \n 'use client' // this directive should be at top of the file, before any imports.\n \n // This is a Client Component\n export default function DashboardLayout({ children }) {\n return (\n
\n

My Dashboard

\n {children}\n
\n )\n }\n \n* Import the `DashboardLayout` into a new `layout.js` file inside the `app` directory.\n \n app/dashboard/layout.js\n \n import DashboardLayout from './DashboardLayout'\n \n // This is a Server Component\n export default function Layout({ children }) {\n return {children}\n }\n \n* You can incrementally move non-interactive parts of `DashboardLayout.js` (Client Component) into `layout.js` (Server Component) to reduce the amount of component JavaScript you send to the client.\n \n\n### [Step 3: Migrating `next/head`](#step-3-migrating-nexthead)\n\nIn the `pages` directory, the `next/head` React component is used to manage `` HTML elements such as `title` and `meta` . In the `app` directory, `next/head` is replaced with the new [built-in SEO support](/docs/app/building-your-application/optimizing/metadata).\n\n**Before:**\n\npages/index.tsx\n\nTypeScript\n\nJavaScriptTypeScript\n\n import Head from 'next/head'\n \n export default function Page() {\n return (\n <>\n \n My page title\n \n \n )\n }\n\n**After:**\n\napp/page.tsx\n\nTypeScript\n\nJavaScriptTypeScript\n\n import { Metadata } from 'next'\n \n export const metadata: Metadata = {\n title: 'My Page Title',\n }\n \n export default function Page() {\n return '...'\n }\n\n[See all metadata options](/docs/app/api-reference/functions/generate-metadata).\n\n### [Step 4: Migrating Pages](#step-4-migrating-pages)\n\n* Pages in the [`app` directory](/docs/app/building-your-application/routing) are [Server Components](/docs/app/building-your-application/rendering/server-components) by default. This is different from the `pages` directory where pages are [Client Components](/docs/app/building-your-application/rendering/client-components).\n* [Data fetching](/docs/app/building-your-application/data-fetching) has changed in `app`. `getServerSideProps`, `getStaticProps` and `getInitialProps` have been replaced with a simpler API.\n* The `app` directory uses nested folders to [define routes](/docs/app/building-your-application/routing/defining-routes) and a special `page.js` file to make a route segment publicly accessible.\n* `pages` Directory\n \n `app` Directory\n \n Route\n \n `index.js`\n \n `page.js`\n \n `/`\n \n `about.js`\n \n `about/page.js`\n \n `/about`\n \n `blog/[slug].js`\n \n `blog/[slug]/page.js`\n \n `/blog/post-1`\n \n\nWe recommend breaking down the migration of a page into two main steps:\n\n* Step 1: Move the default exported Page Component into a new Client Component.\n* Step 2: Import the new Client Component into a new `page.js` file inside the `app` directory.\n\n> **Good to know**: This is the easiest migration path because it has the most comparable behavior to the `pages` directory.\n\n**Step 1: Create a new Client Component**\n\n* Create a new separate file inside the `app` directory (i.e. `app/home-page.tsx` or similar) that exports a Client Component. To define Client Components, add the `'use client'` directive to the top of the file (before any imports).\n * Similar to the Pages Router, there is an [optimization step](/docs/app/building-your-application/rendering/client-components#full-page-load) to prerender Client Components to static HTML on the initial page load.\n* Move the default exported page component from `pages/index.js` to `app/home-page.tsx`.\n\napp/home-page.tsx\n\nTypeScript\n\nJavaScriptTypeScript\n\n 'use client'\n \n // This is a Client Component (same as components in the `pages` directory)\n // It receives data as props, has access to state and effects, and is\n // prerendered on the server during the initial page load.\n export default function HomePage({ recentPosts }) {\n return (\n
\n {recentPosts.map((post) => (\n
{post.title}
\n ))}\n
\n )\n }\n\n**Step 2: Create a new page**\n\n* Create a new `app/page.tsx` file inside the `app` directory. This is a Server Component by default.\n \n* Import the `home-page.tsx` Client Component into the page.\n \n* If you were fetching data in `pages/index.js`, move the data fetching logic directly into the Server Component using the new [data fetching APIs](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating). See the [data fetching upgrade guide](#step-6-migrating-data-fetching-methods) for more details.\n \n app/page.tsx\n \n TypeScript\n \n JavaScriptTypeScript\n \n // Import your Client Component\n import HomePage from './home-page'\n \n async function getPosts() {\n const res = await fetch('https://...')\n const posts = await res.json()\n return posts\n }\n \n export default async function Page() {\n // Fetch data directly in a Server Component\n const recentPosts = await getPosts()\n // Forward fetched data to your Client Component\n return \n }\n \n* If your previous page used `useRouter`, you'll need to update to the new routing hooks. [Learn more](/docs/app/api-reference/functions/use-router).\n \n* Start your development server and visit [`http://localhost:3000`](http://localhost:3000). You should see your existing index route, now served through the app directory.\n \n\n### [Step 5: Migrating Routing Hooks](#step-5-migrating-routing-hooks)\n\nA new router has been added to support the new behavior in the `app` directory.\n\nIn `app`, you should use the three new hooks imported from `next/navigation`: [`useRouter()`](/docs/app/api-reference/functions/use-router), [`usePathname()`](/docs/app/api-reference/functions/use-pathname), and [`useSearchParams()`](/docs/app/api-reference/functions/use-search-params).\n\n* The new `useRouter` hook is imported from `next/navigation` and has different behavior to the `useRouter` hook in `pages` which is imported from `next/router`.\n * The [`useRouter` hook imported from `next/router`](/docs/pages/api-reference/functions/use-router) is not supported in the `app` directory but can continue to be used in the `pages` directory.\n* The new `useRouter` does not return the `pathname` string. Use the separate `usePathname` hook instead.\n* The new `useRouter` does not return the `query` object. Use the separate `useSearchParams` hook instead.\n* You can use `useSearchParams` and `usePathname` together to listen to page changes. See the [Router Events](/docs/app/api-reference/functions/use-router#router-events) section for more details.\n* These new hooks are only supported in Client Components. They cannot be used in Server Components.\n\napp/example-client-component.tsx\n\nTypeScript\n\nJavaScriptTypeScript\n\n 'use client'\n \n import { useRouter, usePathname, useSearchParams } from 'next/navigation'\n \n export default function ExampleClientComponent() {\n const router = useRouter()\n const pathname = usePathname()\n const searchParams = useSearchParams()\n \n // ...\n }\n\nIn addition, the new `useRouter` hook has the following changes:\n\n* `isFallback` has been removed because `fallback` has [been replaced](#replacing-fallback).\n* The `locale`, `locales`, `defaultLocales`, `domainLocales` values have been removed because built-in i18n Next.js features are no longer necessary in the `app` directory. [Learn more about i18n](/docs/app/building-your-application/routing/internationalization).\n* `basePath` has been removed. The alternative will not be part of `useRouter`. It has not yet been implemented.\n* `asPath` has been removed because the concept of `as` has been removed from the new router.\n* `isReady` has been removed because it is no longer necessary. During [static rendering](/docs/app/building-your-application/rendering/server-components#static-rendering-default), any component that uses the [`useSearchParams()`](/docs/app/api-reference/functions/use-search-params) hook will skip the prerendering step and instead be rendered on the client at runtime.\n\n[View the `useRouter()` API reference](/docs/app/api-reference/functions/use-router).\n\n### [Step 6: Migrating Data Fetching Methods](#step-6-migrating-data-fetching-methods)\n\nThe `pages` directory uses `getServerSideProps` and `getStaticProps` to fetch data for pages. Inside the `app` directory, these previous data fetching functions are replaced with a [simpler API](/docs/app/building-your-application/data-fetching) built on top of `fetch()` and `async` React Server Components.\n\napp/page.tsx\n\nTypeScript\n\nJavaScriptTypeScript\n\n export default async function Page() {\n // This request should be cached until manually invalidated.\n // Similar to `getStaticProps`.\n // `force-cache` is the default and can be omitted.\n const staticData = await fetch(`https://...`, { cache: 'force-cache' })\n \n // This request should be refetched on every request.\n // Similar to `getServerSideProps`.\n const dynamicData = await fetch(`https://...`, { cache: 'no-store' })\n \n // This request should be cached with a lifetime of 10 seconds.\n // Similar to `getStaticProps` with the `revalidate` option.\n const revalidatedData = await fetch(`https://...`, {\n next: { revalidate: 10 },\n })\n \n return
...
\n }\n\n#### [Server-side Rendering (`getServerSideProps`)](#server-side-rendering-getserversideprops)\n\nIn the `pages` directory, `getServerSideProps` is used to fetch data on the server and forward props to the default exported React component in the file. The initial HTML for the page is prerendered from the server, followed by \"hydrating\" the page in the browser (making it interactive).\n\npages/dashboard.js\n\n // `pages` directory\n \n export async function getServerSideProps() {\n const res = await fetch(`https://...`)\n const projects = await res.json()\n \n return { props: { projects } }\n }\n \n export default function Dashboard({ projects }) {\n return (\n
    \n {projects.map((project) => (\n
  • {project.name}
  • \n ))}\n
\n )\n }\n\nIn the `app` directory, we can colocate our data fetching inside our React components using [Server Components](/docs/app/building-your-application/rendering/server-components). This allows us to send less JavaScript to the client, while maintaining the rendered HTML from the server.\n\nBy setting the `cache` option to `no-store`, we can indicate that the fetched data should [never be cached](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating). This is similar to `getServerSideProps` in the `pages` directory.\n\napp/dashboard/page.tsx\n\nTypeScript\n\nJavaScriptTypeScript\n\n // `app` directory\n \n // This function can be named anything\n async function getProjects() {\n const res = await fetch(`https://...`, { cache: 'no-store' })\n const projects = await res.json()\n \n return projects\n }\n \n export default async function Dashboard() {\n const projects = await getProjects()\n \n return (\n
    \n {projects.map((project) => (\n
  • {project.name}
  • \n ))}\n
\n )\n }\n\n#### [Accessing Request Object](#accessing-request-object)\n\nIn the `pages` directory, you can retrieve request-based data based on the Node.js HTTP API.\n\nFor example, you can retrieve the `req` object from `getServerSideProps` and use it to retrieve the request's cookies and headers.\n\npages/index.js\n\n // `pages` directory\n \n export async function getServerSideProps({ req, query }) {\n const authHeader = req.getHeaders()['authorization'];\n const theme = req.cookies['theme'];\n \n return { props: { ... }}\n }\n \n export default function Page(props) {\n return ...\n }\n\nThe `app` directory exposes new read-only functions to retrieve request data:\n\n* [`headers()`](/docs/app/api-reference/functions/headers): Based on the Web Headers API, and can be used inside [Server Components](/docs/app/building-your-application/rendering/server-components) to retrieve request headers.\n* [`cookies()`](/docs/app/api-reference/functions/cookies): Based on the Web Cookies API, and can be used inside [Server Components](/docs/app/building-your-application/rendering/server-components) to retrieve cookies.\n\napp/page.tsx\n\nTypeScript\n\nJavaScriptTypeScript\n\n // `app` directory\n import { cookies, headers } from 'next/headers'\n \n async function getData() {\n const authHeader = headers().get('authorization')\n \n return '...'\n }\n \n export default async function Page() {\n // You can use `cookies()` or `headers()` inside Server Components\n // directly or in your data fetching function\n const theme = cookies().get('theme')\n const data = await getData()\n return '...'\n }\n\n#### [Static Site Generation (`getStaticProps`)](#static-site-generation-getstaticprops)\n\nIn the `pages` directory, the `getStaticProps` function is used to pre-render a page at build time. This function can be used to fetch data from an external API or directly from a database, and pass this data down to the entire page as it's being generated during the build.\n\npages/index.js\n\n // `pages` directory\n \n export async function getStaticProps() {\n const res = await fetch(`https://...`)\n const projects = await res.json()\n \n return { props: { projects } }\n }\n \n export default function Index({ projects }) {\n return projects.map((project) =>
{project.name}
)\n }\n\nIn the `app` directory, data fetching with [`fetch()`](/docs/app/api-reference/functions/fetch) will default to `cache: 'force-cache'`, which will cache the request data until manually invalidated. This is similar to `getStaticProps` in the `pages` directory.\n\napp/page.js\n\n // `app` directory\n \n // This function can be named anything\n async function getProjects() {\n const res = await fetch(`https://...`)\n const projects = await res.json()\n \n return projects\n }\n \n export default async function Index() {\n const projects = await getProjects()\n \n return projects.map((project) =>
{project.name}
)\n }\n\n#### [Dynamic paths (`getStaticPaths`)](#dynamic-paths-getstaticpaths)\n\nIn the `pages` directory, the `getStaticPaths` function is used to define the dynamic paths that should be pre-rendered at build time.\n\npages/posts/\\[id\\].js\n\n // `pages` directory\n import PostLayout from '@/components/post-layout'\n \n export async function getStaticPaths() {\n return {\n paths: [{ params: { id: '1' } }, { params: { id: '2' } }],\n }\n }\n \n export async function getStaticProps({ params }) {\n const res = await fetch(`https://.../posts/${params.id}`)\n const post = await res.json()\n \n return { props: { post } }\n }\n \n export default function Post({ post }) {\n return \n }\n\nIn the `app` directory, `getStaticPaths` is replaced with [`generateStaticParams`](/docs/app/api-reference/functions/generate-static-params).\n\n[`generateStaticParams`](/docs/app/api-reference/functions/generate-static-params) behaves similarly to `getStaticPaths`, but has a simplified API for returning route parameters and can be used inside [layouts](/docs/app/building-your-application/routing/pages-and-layouts). The return shape of `generateStaticParams` is an array of segments instead of an array of nested `param` objects or a string of resolved paths.\n\napp/posts/\\[id\\]/page.js\n\n // `app` directory\n import PostLayout from '@/components/post-layout'\n \n export async function generateStaticParams() {\n return [{ id: '1' }, { id: '2' }]\n }\n \n async function getPost(params) {\n const res = await fetch(`https://.../posts/${params.id}`)\n const post = await res.json()\n \n return post\n }\n \n export default async function Post({ params }) {\n const post = await getPost(params)\n \n return \n }\n\nUsing the name `generateStaticParams` is more appropriate than `getStaticPaths` for the new model in the `app` directory. The `get` prefix is replaced with a more descriptive `generate`, which sits better alone now that `getStaticProps` and `getServerSideProps` are no longer necessary. The `Paths` suffix is replaced by `Params`, which is more appropriate for nested routing with multiple dynamic segments.\n\n* * *\n\n#### [Replacing `fallback`](#replacing-fallback)\n\nIn the `pages` directory, the `fallback` property returned from `getStaticPaths` is used to define the behavior of a page that isn't pre-rendered at build time. This property can be set to `true` to show a fallback page while the page is being generated, `false` to show a 404 page, or `blocking` to generate the page at request time.\n\npages/posts/\\[id\\].js\n\n // `pages` directory\n \n export async function getStaticPaths() {\n return {\n paths: [],\n fallback: 'blocking'\n };\n }\n \n export async function getStaticProps({ params }) {\n ...\n }\n \n export default function Post({ post }) {\n return ...\n }\n\nIn the `app` directory the [`config.dynamicParams` property](/docs/app/api-reference/file-conventions/route-segment-config#dynamicparams) controls how params outside of [`generateStaticParams`](/docs/app/api-reference/functions/generate-static-params) are handled:\n\n* **`true`**: (default) Dynamic segments not included in `generateStaticParams` are generated on demand.\n* **`false`**: Dynamic segments not included in `generateStaticParams` will return a 404.\n\nThis replaces the `fallback: true | false | 'blocking'` option of `getStaticPaths` in the `pages` directory. The `fallback: 'blocking'` option is not included in `dynamicParams` because the difference between `'blocking'` and `true` is negligible with streaming.\n\napp/posts/\\[id\\]/page.js\n\n // `app` directory\n \n export const dynamicParams = true;\n \n export async function generateStaticParams() {\n return [...]\n }\n \n async function getPost(params) {\n ...\n }\n \n export default async function Post({ params }) {\n const post = await getPost(params);\n \n return ...\n }\n\nWith [`dynamicParams`](/docs/app/api-reference/file-conventions/route-segment-config#dynamicparams) set to `true` (the default), when a route segment is requested that hasn't been generated, it will be server-rendered and cached.\n\n#### [Incremental Static Regeneration (`getStaticProps` with `revalidate`)](#incremental-static-regeneration-getstaticprops-with-revalidate)\n\nIn the `pages` directory, the `getStaticProps` function allows you to add a `revalidate` field to automatically regenerate a page after a certain amount of time.\n\npages/index.js\n\n // `pages` directory\n \n export async function getStaticProps() {\n const res = await fetch(`https://.../posts`)\n const posts = await res.json()\n \n return {\n props: { posts },\n revalidate: 60,\n }\n }\n \n export default function Index({ posts }) {\n return (\n \n \n \n )\n }\n\nIn the `app` directory, data fetching with [`fetch()`](/docs/app/api-reference/functions/fetch) can use `revalidate`, which will cache the request for the specified amount of seconds.\n\napp/page.js\n\n // `app` directory\n \n async function getPosts() {\n const res = await fetch(`https://.../posts`, { next: { revalidate: 60 } })\n const data = await res.json()\n \n return data.posts\n }\n \n export default async function PostList() {\n const posts = await getPosts()\n \n return posts.map((post) =>
{post.name}
)\n }\n\n#### [API Routes](#api-routes)\n\nAPI Routes continue to work in the `pages/api` directory without any changes. However, they have been replaced by [Route Handlers](/docs/app/building-your-application/routing/route-handlers) in the `app` directory.\n\nRoute Handlers allow you to create custom request handlers for a given route using the Web [Request](https://developer.mozilla.org/docs/Web/API/Request) and [Response](https://developer.mozilla.org/docs/Web/API/Response) APIs.\n\napp/api/route.ts\n\nTypeScript\n\nJavaScriptTypeScript\n\n export async function GET(request: Request) {}\n\n> **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-caching-and-revalidating).\n\n### [Step 7: Styling](#step-7-styling)\n\nIn 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.\n\n* [CSS Modules](/docs/app/building-your-application/styling/css-modules)\n* [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)\n* [Global Styles](/docs/app/building-your-application/styling/css-modules#global-styles)\n* [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)\n* [External Stylesheets](/docs/app/building-your-application/styling/css-modules#external-stylesheets)\n* [Sass](/docs/app/building-your-application/styling/sass)\n\n#### [Tailwind CSS](#tailwind-css)\n\nIf you're using Tailwind CSS, you'll need to add the `app` directory to your `tailwind.config.js` file:\n\ntailwind.config.js\n\n module.exports = {\n content: [\n './app/**/*.{js,ts,jsx,tsx,mdx}', // <-- Add this line\n './pages/**/*.{js,ts,jsx,tsx,mdx}',\n './components/**/*.{js,ts,jsx,tsx,mdx}',\n ],\n }\n\nYou'll also need to import your global styles in your `app/layout.js` file:\n\napp/layout.js\n\n import '../styles/globals.css'\n \n export default function RootLayout({ children }) {\n return (\n \n {children}\n \n )\n }\n\nLearn more about [styling with Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)\n\n[Codemods](#codemods)\n---------------------\n\nNext.js provides Codemod transformations to help upgrade your codebase when a feature is deprecated. See [Codemods](/docs/app/building-your-application/upgrading/codemods) for more information.\n\n[Previous\n\nCodemods\n\n](/docs/pages/building-your-application/upgrading/codemods)\n\n[Next\n\nMigrating from Vite\n\n](/docs/pages/building-your-application/upgrading/from-vite)\n\nWas this helpful?\n\nsupported.\n\nSend"}}},{"rowIdx":244,"cells":{"metadata":{"kind":"string","value":"{\n \"contentLength\": null,\n \"etag\": \"W/\\\"b7a28bbe852b56b44a9f0a6f78ed57bc\\\"\",\n \"lastModifiedHeader\": null,\n \"lastModifiedHtml\": null\n}"},"url":{"kind":"string","value":"https://nextjs.org/docs/pages/building-your-application/deploying/multi-zones"},"markdown":{"kind":"string","value":"Menu\n\nUsing Pages Router\n\nFeatures available in /pages\n\n* [Getting Started](/docs/getting-started)\n \n * [Installation](/docs/getting-started/installation)\n * [Project Structure](/docs/getting-started/project-structure)\n \n\n* [Building Your Application](/docs/app/building-your-application)\n \n * [Routing](/docs/app/building-your-application/routing)\n \n * [Defining Routes](/docs/app/building-your-application/routing/defining-routes)\n * [Pages and Layouts](/docs/app/building-your-application/routing/pages-and-layouts)\n * [Linking and Navigating](/docs/app/building-your-application/routing/linking-and-navigating)\n * [Loading UI and Streaming](/docs/app/building-your-application/routing/loading-ui-and-streaming)\n * [Error Handling](/docs/app/building-your-application/routing/error-handling)\n * [Redirecting](/docs/app/building-your-application/routing/redirecting)\n * [Route Groups](/docs/app/building-your-application/routing/route-groups)\n * [Project Organization](/docs/app/building-your-application/routing/colocation)\n * [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes)\n * [Parallel Routes](/docs/app/building-your-application/routing/parallel-routes)\n * [Intercepting Routes](/docs/app/building-your-application/routing/intercepting-routes)\n * [Route Handlers](/docs/app/building-your-application/routing/route-handlers)\n * [Middleware](/docs/app/building-your-application/routing/middleware)\n * [Internationalization](/docs/app/building-your-application/routing/internationalization)\n \n * [Data Fetching](/docs/app/building-your-application/data-fetching)\n \n * [Fetching, Caching, and Revalidating](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)\n * [Server Actions and Mutations](/docs/app/building-your-application/data-fetching/server-actions-and-mutations)\n * [Data Fetching Patterns and Best Practices](/docs/app/building-your-application/data-fetching/patterns)\n \n * [Rendering](/docs/app/building-your-application/rendering)\n \n * [Server Components](/docs/app/building-your-application/rendering/server-components)\n * [Client Components](/docs/app/building-your-application/rendering/client-components)\n * [Composition Patterns](/docs/app/building-your-application/rendering/composition-patterns)\n * [Edge and Node.js Runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes)\n \n * [Caching](/docs/app/building-your-application/caching)\n * [Styling](/docs/app/building-your-application/styling)\n \n * [CSS Modules](/docs/app/building-your-application/styling/css-modules)\n * [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)\n * [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)\n * [Sass](/docs/app/building-your-application/styling/sass)\n \n * [Optimizing](/docs/app/building-your-application/optimizing)\n \n * [Images](/docs/app/building-your-application/optimizing/images)\n * [Videos](/docs/app/building-your-application/optimizing/videos)\n * [Fonts](/docs/app/building-your-application/optimizing/fonts)\n * [Metadata](/docs/app/building-your-application/optimizing/metadata)\n * [Scripts](/docs/app/building-your-application/optimizing/scripts)\n * [Bundle Analyzer](/docs/app/building-your-application/optimizing/bundle-analyzer)\n * [Lazy Loading](/docs/app/building-your-application/optimizing/lazy-loading)\n * [Analytics](/docs/app/building-your-application/optimizing/analytics)\n * [Instrumentation](/docs/app/building-your-application/optimizing/instrumentation)\n * [OpenTelemetry](/docs/app/building-your-application/optimizing/open-telemetry)\n * [Static Assets](/docs/app/building-your-application/optimizing/static-assets)\n * [Third Party Libraries](/docs/app/building-your-application/optimizing/third-party-libraries)\n * [Memory Usage](/docs/app/building-your-application/optimizing/memory-usage)\n \n * [Configuring](/docs/app/building-your-application/configuring)\n \n * [TypeScript](/docs/app/building-your-application/configuring/typescript)\n * [ESLint](/docs/app/building-your-application/configuring/eslint)\n * [Environment Variables](/docs/app/building-your-application/configuring/environment-variables)\n * [Absolute Imports and Module Path Aliases](/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases)\n * [MDX](/docs/app/building-your-application/configuring/mdx)\n * [src Directory](/docs/app/building-your-application/configuring/src-directory)\n * [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)\n * [Content Security Policy](/docs/app/building-your-application/configuring/content-security-policy)\n \n * [Testing](/docs/app/building-your-application/testing)\n \n * [Vitest](/docs/app/building-your-application/testing/vitest)\n * [Jest](/docs/app/building-your-application/testing/jest)\n * [Playwright](/docs/app/building-your-application/testing/playwright)\n * [Cypress](/docs/app/building-your-application/testing/cypress)\n \n * [Authentication](/docs/app/building-your-application/authentication)\n * [Deploying](/docs/app/building-your-application/deploying)\n \n * [Production Checklist](/docs/app/building-your-application/deploying/production-checklist)\n * [Static Exports](/docs/app/building-your-application/deploying/static-exports)\n \n * [Upgrading](/docs/app/building-your-application/upgrading)\n \n * [Codemods](/docs/app/building-your-application/upgrading/codemods)\n * [App Router Migration](/docs/app/building-your-application/upgrading/app-router-migration)\n * [Version 14](/docs/app/building-your-application/upgrading/version-14)\n * [Migrating from Vite](/docs/app/building-your-application/upgrading/from-vite)\n * [Migrating from Create React App](/docs/app/building-your-application/upgrading/from-create-react-app)\n \n \n\n* [API Reference](/docs/app/api-reference)\n \n * [Components](/docs/app/api-reference/components)\n \n * [Font](/docs/app/api-reference/components/font)\n * [](/docs/app/api-reference/components/image)\n * [](/docs/app/api-reference/components/link)\n * [