所以我对 NextJS 领域还很陌生,我之前使用的是简单的反应,但我发现需要 ISR,所以我来到 NextJS,因为它到目前为止是一个好的过渡。
我有以下路线结构:
/tutorials/minecraft/[version]/[tutorial]
现在我需要做的是使用这两个动态部分(
version
和 tutorial
)收集数据。我尝试了很多不同的东西,弄乱了 useRouter
和东西。但它总是给我一些问题。
现在,这就是我所拥有的(简化版本,因为下面有很多我知道非常好的内容):
async function getTutorial(version, tutorial) {
const response = await fetch(
`https://raw.githubusercontent.com/DaRealTurtyWurty/Minecraft-Tutorials/main/${version}/${tutorial}.json`,
{
next: { revalidate: 10 }
}
);
return await response.json();
}
export default async function Page({ params }) {
const { version, tutorial } = params;
const tutorialData = await getTutorial(version, tutorial);
let content = deserialize(tutorialData);
return <div>
{content}
</div>
}
这是控制台中发生的事情:
ready - started server on 0.0.0.0:3000, url: http://localhost:3000
warn - You have enabled experimental feature (appDir) in next.config.js.
info - Thank you for testing `appDir` please leave your feedback at https://nextjs.link/app-feedback
warn - Experimental features are not covered by semver, and may cause unexpected or broken application behavior. Use at your own risk.
event - compiled client and server successfully in 1821 ms (263 modules)
wait - compiling...
wait - compiling /tutorials/minecraft/[version]/[tutorial]/page (client and server)...
PS E:\turtywurty-dev-next>
它只是崩溃。没有错误或任何东西,无论是在服务器上还是在浏览器上。我已经尝试了很多东西,使用路由器获取参数等等。但没有任何帮助,它仍然崩溃。