I am attempting to add a favicon to a React-based website that I made using webpack. It has been a total nightmare to add a favicon and I have tried many solutions to no ava
Browsers look for your favicon in /favicon.ico
, so that's where it needs to be. You can double check if you've positioned it in the correct place by navigating to [address:port]/favicon.ico
and seeing if your icon appears.
In dev mode, you are using historyApiFallback, so will need to configure webpack to explicitly return your icon for that route:
historyApiFallback: {
index: '[path/to/index]',
rewrites: [
// shows favicon
{ from: /favicon.ico/, to: '[path/to/favicon]' }
]
}
In your server.js
file, try explicitly rewriting the url:
app.configure(function() {
app.use('/favicon.ico', express.static(__dirname + '[route/to/favicon]'));
});
(or however your setup prefers to rewrite urls)
I suggest generating a true .ico
file rather than using a .png
, since I've found that to be more reliable across browsers.