Skip to content

页面

创建你在Next.js中的第一个页面。

相关链接:

  • app/building-your-application/routing/layouts-and-templates
  • app/building-your-application/routing/linking-and-navigating

页面是针对路由唯一的UI。你可以通过从page.js文件默认导出一个组件来定义一个页面。

例如,要创建你的index页面,在app目录中添加page.js文件:

page.js特殊文件

tsx
// `app/page.tsx` 是 `/` URL的UI
export default function Page() {
  return <h1>Hello, Home page!</h1>
}
jsx
// `app/page.js` 是 `/` URL的UI
export default function Page() {
  return <h1>Hello, Home page!</h1>
}

然后,要创建更多页面,创建一个新文件夹并在其中添加page.js文件。例如,要为/dashboard路由创建页面,创建一个名为dashboard的新文件夹,并在其中添加page.js文件:

tsx
// `app/dashboard/page.tsx` 是 `/dashboard` URL的UI
export default function Page() {
  return <h1>Hello, Dashboard Page!</h1>
}
jsx
// `app/dashboard/page.js` 是 `/dashboard` URL的UI
export default function Page() {
  return <h1>Hello, Dashboard Page!</h1>
}

须知