提供网站图标next.js

node.js React.js

Pro西门

2020-03-24

我正在使用样板Next.js启动器在中index.js,快速应用程序的实例定义为expressApp我只是尝试使用我的网站图标serve-favicon,而没有运气:

expressApp.use(favicon(path.join(__dirname, "static", "brand", "favicon.ico")));

检查了正在解析的路径,它是正确的。next.js的实现express有何不同?

第3383篇《提供网站图标next.js》来自Winter(https://github.com/aiyld/aiyld.github.io)的站点

1个回答
Itachi凯 2020.03.24

serve-favicon存储库:

注意此模块专用于服务“默认的,隐式图标” GET /favicon.ico对于需要HTML标记的其他特定于供应商的图标,需要其他中间件来提供相关文件,例如serve-static

因此,此程序包无法在其他路径中提供favicon,因为这将需要添加标记。要解决此问题,link请在pages/_document.js模板添加标签

<Head>
  <link rel="icon" type="image/x-icon" href="/brand/favicon.ico" />
</Head>

在将serve-favicon代码保存index.js文件中的同时:

expressApp.use(favicon(path.join(__dirname, "static", "brand", "favicon.ico")));

问题类别

JavaScript Ckeditor Python Webpack TypeScript Vue.js React.js ExpressJS KoaJS CSS Node.js HTML Django 单元测试 PHP Asp.net jQuery Bootstrap IOS Android