添加或生成一个符合 Web Manifest 规范 的 manifest.(json|webmanifest) 文件,放置在 app 目录的 根目录 中,以便为浏览器提供关于你的 Web 应用程序的信息。
{
"name": "My Next.js Application",
"short_name": "Next.js App",
"description": "An application built with Next.js",
"start_url": "/"
// ...
}添加一个 manifest.js 或 manifest.ts 文件,它会返回一个 Manifest 对象。
值得注意的是:
manifest.js是一种特殊的路由处理程序,默认情况下会被缓存,除非它使用了 动态 API 或 动态配置 选项。
import type { MetadataRoute } from 'next'
export default function manifest(): MetadataRoute.Manifest {
return {
name: 'Next.js App',
short_name: 'Next.js App',
description: 'Next.js App',
start_url: '/',
display: 'standalone',
background_color: '#fff',
theme_color: '#fff',
icons: [
{
src: '/favicon.ico',
sizes: 'any',
type: 'image/x-icon',
},
],
}
}export default function manifest() {
return {
name: 'Next.js App',
short_name: 'Next.js App',
description: 'Next.js App',
start_url: '/',
display: 'standalone',
background_color: '#fff',
theme_color: '#fff',
icons: [
{
src: '/favicon.ico',
sizes: 'any',
type: 'image/x-icon',
},
],
}
}Manifest 对象包含一个广泛的选项列表,这些选项可能会因新的 Web 标准而更新。有关所有当前选项的信息,如果你使用 TypeScript,请查阅你代码编辑器中的 MetadataRoute.Manifest 类型,或参考 MDN 文档。