我有一个nextjs应用程序,我在app/layout.tsx上应用了谷歌字体:

问题:这种字体只适用于/,而不适用于其他页面. layout.tsx是不是适用于所有的子元素?

import "styles/global.css";
import {Metadata} from "next";
import {Gabarito} from "next/font/google";

const gabarito = Gabarito({
    weight: ["500", "600", "700", "900"],
    style: ["normal"],
    display: "swap",
    subsets: ["latin"],
});

export default function RootLayout({children}: {children: React.ReactNode}) {
    return (
        <html lang='fr' className={gabarito.className}>
            <body>{children}</body>
        </html>
    );
}

export const metadata: Metadata = {
    title: "...",
    description: "...",
};

推荐答案

Problem :

此字体仅适用于/,不适用于其他页面.Layout.tsx是否适用于所有 children

Possible Causes :

  • Tailwind CSS配置不正确.
  • 缺少此行中的'./pages/**/*.{js,ts,jsx,tsx,mdx}' tailwind.config.js内容密钥.

Solution :

根据官方文件,

转到您的tailwind.config.js添加更新content密钥(&A)

content: [
    './app/**/*.{js,ts,jsx,tsx,mdx}', // Note the addition of the `app` directory.
    './pages/**/*.{js,ts,jsx,tsx,mdx}',
    './components/**/*.{js,ts,jsx,tsx,mdx}',
 
    // Or if using `src` directory:
    './src/**/*.{js,ts,jsx,tsx,mdx}',
  ],

同样在你的app/globals.css岁时,别忘了加上:

@tailwind base;
@tailwind components;
@tailwind utilities;

tailwind.config.js :

/** @type {import('tailwindcss').Config} */
module.exports = {
  content: [

    './app/**/*.{js,ts,jsx,tsx,mdx}', // Note the addition of the `app` directory.
    './pages/**/*.{js,ts,jsx,tsx,mdx}',
    './components/**/*.{js,ts,jsx,tsx,mdx}',

    // Or if using `src` directory:
    './src/**/*.{js,ts,jsx,tsx,mdx}',
  ],
  theme: {
    extend: {

    },
  },
  plugins: [],
}

100

100

Reactjs相关问答推荐

在react.js的条形图中获取错误&unfined是不可迭代的

如何在React中的textarea中显示字符数?

react 挂钩-使用有效澄清

为什么查询错误在处理后仍出现在控制台中?RTK查询+ React

在transformResponse中使用来自其他查询的缓存

Reaction路由-如何在布局路由内呈现&q;/:id&q;路由

Github 操作失败:发布 NPM 包

Javascript - 正则表达式不适用于 MAC OS - 编码?

获取 不能显示为 的后代.错误,但不太确定如何构建我的代码以避免此警告

在MongoDB中,如何获取最后N条记录中字段不为空或不为空字符串的数据

根据其中的值不同地react setState 更新状态

在按钮单击中将动态参数传递给 React Query

部署到github pages时请求路径错误

React v6 中的公共和私有路由

Cypress 组件测试不渲染react 组件(但它的内容)

导航到屏幕时,react 本机上下文状态变为未定义

在 redux 工具包中使用 dispatch 发送多个操作

调用函数以获取数据并在数据到达时导航到链接

Map 函数只返回 Array 中的图像

在 Nextjs 中使用 useEffect 随机化一个数组