【发布时间】:2021-07-13 06:20:38
【问题描述】:
我知道很多人已经问过同样的问题,但他们的回答都对我有用...
我遇到了这个错误:
If you want to write it to the DOM, pass a string instead: className="false" or className={value.toString()}.
If you used to conditionally omit it with className={condition && value}, pass className={condition ? value : undefined} instead.
at a
at Link (webpack-internal:///./node_modules/next/dist/client/link.js:79:19)
at li
at SellerSidebarData (webpack-internal:///./components/sellercomp/SSData.js:17:3)
at ul
at div
at div
at SellerSidebar (webpack-internal:///./components/sellercomp/SellerSidebar.js:31:20)
at div
at SellerLayout (webpack-internal:///./components/sellercomp/SellerLayout.js:22:3)
at MyApp (webpack-internal:///./pages/_app.js:55:3)
at AppContainer (/node_modules/next/dist/next-server/server/render.js:27:952)
这是我的代码:
import React from 'react';
import Link from 'next/link';
import { useRouter } from 'next/router';
const SellerSidebarData = ({ classPath, path, icon, title }) => {
const router = useRouter();
return (
<li>
<Link href={path}>
<a
className={
router.pathname == classPath &&
'wave-effect waves-effect waves-button active'
}
>
<i aria-hidden className={`width18 textCenter ${icon}`}></i>
{title}
</a>
</Link>
</li>
);
};
export default SellerSidebarData;
顺便说一句,我知道三个文件有错误,但如果你能回答我给的代码,我很可能会回答其他文件...提前非常感谢!!!
【问题讨论】:
-
如果您过去使用
className={condition && value}有条件地省略它,请改为通过className={condition ? value : undefined}。
标签: javascript reactjs next.js