简体   繁体   English

尝试查看帖子时出现 Nextjs 404

[英]Nextjs 404 when trying to view post

I used all of the code from this tutorial ( link ) for a nextjs app with a custom server, and it works, but only partially, I can add stuff but when I click on some of the content it shows a 404 error.我将本教程中的所有代码( 链接)用于带有自定义服务器的 nextjs 应用程序,它可以工作,但只能部分运行,我可以添加内容,但是当我单击某些内容时,它会显示 404 错误。 Works perfectly with CRA so my guess is that I need to do something in server.js perhaps or take a different approach with routing?与 CRA 完美配合,所以我的猜测是我可能需要在server.js 中做一些事情,或者对路由采取不同的方法? I tried this:我试过这个:

<Link href={`/show?=${board.key}`}>{board.title}</Link>

but then an error pops up saying但随后弹出一个错误说

typeerror: cannot read property 'params' of undefined.类型错误:无法读取未定义的属性“参数”。

Any idea how I can make this code work with nextjs?知道如何使此代码与 nextjs 一起使用吗? I'm so desperate, this is my 4th day trying to get it to work.我太绝望了,这是我尝试让它工作的第 4 天。

Define all routes in server.js .server.js 中定义所有路由。 In package.json file replace "dev": "next" with "dev": "node server.js"在 package.json 文件中将"dev": "next"替换为"dev": "node server.js"

static async getInitialProps(ctx) {
   const {query} = ctx;
   return query;
}

constructor(props){
   super(props);
   console.log(props);
}

Check props you will get an id from that.检查道具你会从中得到一个id。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM