[英]next.js Head imported from next/head doesn't work properly on share pages
[英]Next.js - Head element doesn't work
我有一個非常簡單的布局組件,它使用 Next.js 附帶的Head
組件:
import React from 'react';
import { Container } from 'semantic-ui-react';
import { Head } from 'next/head';
import Header from './Header';
const Layout = ({ children }) => (
<Container>
<Head>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.3.1/semantic.min.css" />
</Head>
<Header />
{children}
<h1>Footer</h1>
</Container>
);
export default Layout;
這給了我一個錯誤:
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
at invariant (/app/node_modules/fbjs/lib/invariant.js:42:15)
at ReactDOMServerRenderer.render (/app/node_modules/react-dom/cjs/react-dom-server.node.development.js:2522:7)
at ReactDOMServerRenderer.read (/app/node_modules/react-dom/cjs/react-dom-server.node.development.js:2354:19)
at renderToString (/app/node_modules/react-dom/cjs/react-dom-server.node.development.js:2726:25)
at renderPage (/app/node_modules/next/dist/server/render.js:275:26)
at Function.getInitialProps (/app/node_modules/next/dist/server/document.js:67:25)
at _callee$ (/app/node_modules/next/dist/lib/utils.js:111:30)
at tryCatch (/app/node_modules/regenerator-runtime/runtime.js:62:40)
at Generator.invoke [as _invoke] (/app/node_modules/regenerator-runtime/runtime.js:296:22)
at Generator.prototype.(anonymous function) [as next] (/app/node_modules/regenerator-runtime/runtime.js:114:21)
at step (/app/node_modules/@babel/runtime/helpers/asyncToGenerator.js:12:30)
at _next (/app/node_modules/@babel/runtime/helpers/asyncToGenerator.js:27:9)
at /app/node_modules/@babel/runtime/helpers/asyncToGenerator.js:34:7
at new Promise (<anonymous>)
at new F (/app/node_modules/core-js/library/modules/_export.js:36:28)
at /app/node_modules/@babel/runtime/helpers/asyncToGenerator.js:7:12
at loadGetInitialProps (/app/node_modules/next/dist/lib/utils.js:90:31)
at _callee3$ (/app/node_modules/next/dist/server/render.js:296:51)
at tryCatch (/app/node_modules/regenerator-runtime/runtime.js:62:40)
at Generator.invoke [as _invoke] (/app/node_modules/regenerator-runtime/runtime.js:296:22)
at Generator.prototype.(anonymous function) [as next] (/app/node_modules/regenerator-runtime/runtime.js:114:21)
at step (/app/node_modules/@babel/runtime/helpers/asyncToGenerator.js:12:30)
如果我不使用Head
組件,錯誤就會消失。
我在 Github 上的 Next.js 頁面上找不到一些相關的問題,在 Google 上也找不到相關的內容。
有什么想法嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.