【发布时间】:2020-02-01 14:45:10
【问题描述】:
我正在寻找我在这段代码中做错了什么,但你无法解决它。 我需要在 getInitialPops 中使用我的 query.id 来感染一些内容。提取有效,但在我的捕获中,我收到了这个错误:
FetchError: invalid json response body at https://url/resume-true.json reason: Unexpected token < in JSON at position 0
原始端点:
https://url/resume-${query.id}.json
当我 console.log 返回 query.id 时,首先
slug-5 (this is the rigth one)
第二个:
true (I dont'know were this came from)
这是我的 getInitialProps
channelRouter.getInitialProps = async ({ query }) => {
console.log("query**", query.id);
try {
const res = await fetch(
`https://url/resume-${query.id}.json`
);
let data = await res.json();
return { data };
} catch (e) {
console.log(`${e}`);
}
};
有什么想法吗? 谢谢!!
【问题讨论】:
标签: javascript reactjs next.js