【发布时间】:2023-01-29 17:35:54
【问题描述】:
在我的 nextJS 应用程序中,我需要根据从数据库接收到的用户偏好动态加载样式表。
因此,在我的页面中,我将其添加到 Head (next/head) 中,如下所示:
<Head>
<link rel="stylesheet" href={`/fonts/${type}/stylesheet.css`}></link>
</Head>
但是,这在开发模式的控制台中给我一个警告:
Do not add stylesheets using next/head (see <link rel="stylesheet"> tag with href="/fonts/cal/stylesheet.css"). Use Document instead.
See more info here: https://nextjs.org/docs/messages/no-stylesheets-in-head-component
样式表本身包含字体:
@font-face {
font-family: "Cal Sans";
src: url("CalSans-SemiBold.woff2") format("woff2"),
url("CalSans-SemiBold.woff") format("woff");
font-weight: 600;
font-style: normal;
font-display: swap;
}
由于用户的首选项存储在数据库中,并且我通过查询收到此值,因此我不知道如何将其添加到 Document.js 文件中。
我真的很感激这方面的任何帮助。
【问题讨论】:
标签: javascript reactjs next.js