我遵循了文档,但图标没有出现。我该如何解决它?
这是我的来源
//layout.tsx
import './styles'
import type { Metadata } from 'next'
import { Inter } from 'next/font/google'
const inter = Inter({ subsets: ['latin'] })
export const metadata: Metadata = {
title: 'profile-card',
description: '프로필 카드 페이지',
}
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="ko">
<head>
<link rel="icon" href="/favicon.ico" sizes="any" />
</head>
<body className={inter.className}>{children}</body>
</html>
)
}
我尝试了Next.js文档。
在项目根目录中的 app 文件夹旁边创建一个
public
文件夹,并将 favicon.ico 放入其中。
现在 favicon.ico 应该可以通过
http://localhost:3001/public/favicon.ico
访问
然后将以下
rewrite
添加到项目根目录中的 next.config.js 中:
module.exports = {
// ...
async rewrites() {
return [
{
source: '/:path*/favicon.ico',
destination: '/favicon.ico',
},
]
},
// ...
}
这会导致网站图标无论在哪里都可用
http://localhost:3001/favicon.ico
有了这个,您的网站应该能够检测到该图标。