add favicon to next js static site
Create a
public
directory in the root of your Next.js project if it doesn't already exist.Inside the
public
directory, add your favicon.ico file. You can use an online tool to generate a favicon.ico file from an image.Open your
next.config.js
file in the root of your project (create one if it doesn't exist).If you don't have a module.exports block in your
next.config.js
file, add one.
module.exports = {
// Your other configuration options go here
};
- Inside the
module.exports
block, add the following code to configure Next.js to use the favicon:
module.exports = {
// Your other configuration options go here
// Configure the Next.js app to use a custom favicon
async headers() {
return [
{
source: '/favicon.ico',
headers: [
{
key: 'Content-Type',
value: 'image/x-icon',
},
],
},
];
},
};
Save your changes to the
next.config.js
file.Start or restart your Next.js development server:
npm run dev
Your favicon should now be visible when you access your Next.js static site.