Reactjs 从“getServerSideProps”返回了其他密钥。从getServerSideProps返回notFound对象

Reactjs 从“getServerSideProps”返回了其他密钥。从getServerSideProps返回notFound对象,reactjs,next.js,Reactjs,Next.js,我有下一个应用程序。我需要在[slug]页面中实现路由不匹配时的逻辑,然后显示404页面错误 据我所知,在接下来的Show404页面中,我需要返回值为true的notFound对象 所以问题是当我从getServerSideProps返回{notFound:true}时,为什么会出现这个错误 错误:从getServerSideProps返回了其他密钥。 用于组件的属性必须嵌套在 道具键,例如: 返回{props:{title:'My title',content:'…'} 需要移动的键:找不到

我有下一个应用程序。我需要在[slug]页面中实现路由不匹配时的逻辑,然后显示404页面错误

据我所知,在接下来的Show404页面中,我需要返回值为
true
notFound
对象

所以问题是当我从
getServerSideProps
返回
{notFound:true}
时,为什么会出现这个错误

错误:从
getServerSideProps
返回了其他密钥。 用于组件的属性必须嵌套在
道具
键,例如:

返回{props:{title:'My title',content:'…'}

需要移动的键:找不到

代码:

只有当我在
url
中写东西,并有意识地将slug页面从正确更改为不正确时,它才会出错。例如,从
localhost/page/1
localhost/page/blabla


在这种情况下,当我将路由更改为错误时,如果这种情况
(如果(!slug | | data.statusCode==404))
。下一版本9.5.2

您正在使用下一版本9.5.2。最早支持
notFound
的版本是10.0.0。从:


因此,您必须升级才能使用该逻辑。

您确定这是导致错误的代码吗?它看起来很好,除了奇怪的等待,但它应该像预期的那样工作。你用的是什么版本的Next?@Danila只有当我在url中写了一些东西并有意识地将我的slug页面从正确改为不正确时,它才会出错。例如,从
localhost/page/1
localhost/page/blabla
。在这种情况下,当我将路由更改为错误时,如果这种情况
(如果(!slug | | data.statusCode==404))
。下一版本9.5.2。最新答案谢谢你的帮助,祝你好运。
export const getServerSideProps: GetServerSideProps = async ({ params, req }) => {

    const { slug } =  params;

    // first request
    const data = await (await fetch(`${process.env.NEXT_PUBLIC_API_HOST}/${slug}`)).json();

    // second request
    const user = await fetch(`${process.env.NEXT_PUBLIC_API_HOST}`, {
        method: "GET",
        headers: {
            'Authorization': 'Bearer ' + "jwt",
            'Content-Type': 'application/json',
        },
    });
    const userInfo = await user.json();


    if ( !slug || data.statusCode === 404 ) return { notFound: true }

    return {
        props: {
            title: "something",
            // my props in here
        },
    }
}