admin 管理员组文章数量: 1086019
can you please help me to resolve a error Only absolute URLs are supported in nextjs .I am trying to fetch data from server
export async function getStaticProps({
params,
preview = false,
previewData = {}
}) {
console.log("-----");
const res = await fetch("/api/basecss/");
const stylesheet = await res.text(); // Converts response data to text
return {
revalidate: 200,
props: {
stylesheet
}
};
}
here is my code =/pages/index.js:332-639
I am getting this error TypeError: Only absolute URLs are supported
can you please help me to resolve a error Only absolute URLs are supported in nextjs .I am trying to fetch data from server
export async function getStaticProps({
params,
preview = false,
previewData = {}
}) {
console.log("-----");
const res = await fetch("/api/basecss/");
const stylesheet = await res.text(); // Converts response data to text
return {
revalidate: 200,
props: {
stylesheet
}
};
}
here is my code https://codesandbox.io/s/naughty-platform-1xket?file=/pages/index.js:332-639
I am getting this error TypeError: Only absolute URLs are supported
Share Improve this question asked Jan 13, 2021 at 1:18 user944513user944513 12.8k52 gold badges185 silver badges348 bronze badges 2-
1
This: Next.js - Error: only absolute urls are supported and this issue should answer your question. The error is ing from
fetch
, and it tells you what the problem is: relative URLs aren't supported. You need a whole URL, not just a path. – Zac Anger Commented Jan 13, 2021 at 1:24 -
1
@ZacAnger Thanks for answering .but issue is how i use
getStaticProps
in build time. – user944513 Commented Jan 13, 2021 at 1:36
1 Answer
Reset to default 3The string you're passing into fetch
on line 23 is a relative URL (i.e. it's missing the protocol and domain name, which might be http://localhost:3000/api/basecss or similar)
You need to reference the API endpoint as an absolute URL, including that information. This post has some information on how you can do so
Next.js - Error: only absolute urls are supported
本文标签: javascriptErrorOnly absolute URLs are supported in nextjsStack Overflow
版权声明:本文标题:javascript - Error : Only absolute URLs are supported in nextjs - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744098206a2533292.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论