扫码一下
查看教程更方便
在 next.js 中,我们可以借助内置的 react 组件非常轻松地修改每个 react 页面的 head 部分。
让我们修改 pages 章节中使用的 nextjs 项目。
更新 index.js 如下
index.js
import link from 'next/link' import head from 'next/head' function homepage() { return ( <>
welcome to next.js! welcome to next.js!
) } export default homepage
更新 first.js 如下
first.js
import link from 'next/link' import head from 'next/head' export default function firstpost() { return ( <>
my first post ) }
在这里,我们在 index.js 文件中添加了对 jiyik_logo.png 的引用。
运行以下命令启动服务器
$ npm run dev
> nextjs@1.0.0 dev //workspace/node/nextjs
> next dev
ready - started server on 0.0.0.0:3000, url: http://localhost:3000
event - compiled client and server successfully in 420 ms (110 modules)
在浏览器中打开 localhost:3000 ,我们将看到以下输出。