Next.js Discord

Discord Forum

dynamic favicon for routes

Answered
Korat posted this in #help-forum
Open in Discord
Avatar
KoratOP
hi, is it possible to make a dynamic favicon for routes? i want to use different favicons for every page. I've searched it but nothing worked
Answered by B33fb0n3
yes you can do this by creating multiple metadata objects inside your different pages. You also want it dynamic, so you can [use the generateMetadata function](https://nextjs.org/docs/app/api-reference/functions/generate-metadata). Like that you can add a icon url too and have dynamic icons the pages that you want
View full answer

10 Replies

Avatar
yes you can do this by creating multiple metadata objects inside your different pages. You also want it dynamic, so you can [use the generateMetadata function](https://nextjs.org/docs/app/api-reference/functions/generate-metadata). Like that you can add a icon url too and have dynamic icons the pages that you want
Answer
Avatar
KoratOP
the first way that you said didn't work
how should I specify the favicon directory?
Avatar
your metadata could look like this:
{
    // ...other meta tags
    icons: ['https://static-00.iconduck.com/assets.00/star-icon-2048x2048-vsj84iil.png'], // the path to your file
};

Now you only need to add multiple metadatas to different files and they will automatically change when you change the page/layout
Avatar
KoratOP
like that?
Image
Avatar
no, more like this: https://nextjs-forum.com/post/1299746621583785994#message-1299781751962468433
So instead of providing an object, provide it as array

don't ask me why it's an array, but it's an array
Avatar
KoratOP
Ive tried using icons as png inside my project's directory but didnt work. Im using static website link instead.
It has worked with that.
Avatar
Happy to help