我正在尝试从后端获取 udemy 课程,但当我使用图像组件时,我不断收到此错误。
错误:next/image
上的 src 属性 (
https://img-b.udemycdn.com/course/750x422/1943926_e313.jpg) 无效,主机名“img-b.udemycdn.com”未在您的图像下配置
next.config.js
这是下一个.config.js
const nextConfig = {
reactStrictMode: true,
swcMinify: true,
optimizeFonts: true,
images: {
remotePatterns: [
{
protocol: 'https',
hostname: 'img-b.udemycdn.com',
pathname: '**',
},
],
},
};
module.exports = nextConfig;
将
pathname
留空,并添加一个空字符串作为 port
属性,如下所示:
const nextConfig = {
reactStrictMode: true,
swcMinify: true,
optimizeFonts: true,
images: {
remotePatterns: [
{
protocol: 'https',
hostname: 'img-b.udemycdn.com',
port: '',
},
],
},
};