Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding favicon to <Helmet/> in React

I was trying to add a favicon in the <Helmet/> tag of a React App

my current <Helmet/> tag looks like this.

<Helmet
        title="ABC"
        meta={[
            { name: "ABC", content: "ABC" }
        ]}
        links={
        rel='icon',
        type='image/png',
        sizes='16x16',
        href={require('favicon.ico')}
        }

/>

But I'm getting an error about an unexpected token, any inputs on how to add a favicon? Thanks for the help in advance.

like image 612
UWGOOSE Avatar asked Apr 06 '18 22:04

UWGOOSE


2 Answers

Try this please. You written wrong keyword(links => link)

<Helmet
        title="ABC"
        meta={[
            { name: "ABC", content: "ABC" }
        ]}
        link={[
              {"rel": "icon", 
               "type": "image/png", 
               "href": "favicon.ico"
              }
             ]}
/>
like image 96
sekercan cepni Avatar answered Sep 16 '22 13:09

sekercan cepni


If you are using react-helmet in your project then I think one issue with your code is that link should be singular, not the plural 'links'

Try this

import Helmet from 'react-helmet'

...

<Helmet>
  <title>ABC</title>
  <meta name="ABC" content: "ABC" />
  <link rel="icon" type="image/png" href="favicon.ico" sizes="16x16" />
</Helmet>
like image 37
Lucas Kellner Avatar answered Sep 19 '22 13:09

Lucas Kellner