【发布时间】:2020-10-20 19:24:07
【问题描述】:
我在 Next.js 版本 9.4.4 中开发了一个应用程序。我的文件夹结构如下图:
pages
[id]
index.js
index.js
当我向localhost:3000/something 发出请求时,它会转到索引页面,当我在根索引页面中记录此信息时,我无法获取/这里是根索引文件的代码
Index.getInitialProps = (ctx) => {
console.log(ctx.headers, ctx.pathname, ctx.url);
return {};
};
输出是
undefined / undefined
【问题讨论】:
-
console.log(ctx) 显示什么?
-
@SterlinV 这是 ctx 输出的链接justpaste.it/2lr8s
-
@RasoulSalehi 你在当前页面添加了 getInitialProps 吗?
-
@visizky 我不知道您所说的当前页面是什么意思,如果您的意思是我添加了,则在 id 页面中并且没有记录任何内容,因为它转到根索引页面,这是我添加 getIntialProps 的地方是该页面上的代码。并且都有 getInitialProps
-
我不知道为什么 /something 没有在 id 页面或索引页面的任何地方传递
标签: next.js