Next.js不通过路径参数

时间:2020-10-20 05:43:50

标签: next.js

我在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

1 个答案:

答案 0 :(得分:0)

您正在使用动态路线。因此,您的“路径”将位于ctx.query中(在您的情况下为ctx.query.id)