小编Shl*_*ain的帖子

在 Next.js 中使用“使用客户端”时无法使用元数据更改标题

/demo我的 Next.js 应用程序中有一条路线13,它使用App Router. 但我无法更改页面的标题(我得到的当前标题是 localhost:3000/demo)。

我有以下代码。

/demo/page.js

'use client'

 ....

export const metadata = {
  title: 'Demo - ModalJS',
};

export default Demo(){
 return ...
}
Run Code Online (Sandbox Code Playgroud)

'use client'正在造成问题,因为当我删除它时,标题会发生变化,但问题是我无法删除它,因为该组件使用onClick它会在没有“使用客户端”的情况下给出错误

里面的代码Demo如下:

export default function Demo() {
    

    const [title, setTitle] = useState("Title of your modal");
    const [desc, setDesc] = useState("You description goes here");
    const [theme, setTheme] = useState("light");

    const handleclick = ()=>{
        const modal = new ModalJS( ... stuff related …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs next.js

14
推荐指数
2
解决办法
1万
查看次数

标签 统计

javascript ×1

next.js ×1

reactjs ×1