我正在try 将我的getserverside props()移植到next13,并且需要使用url.如何获取参数(从目录 struct )或url.我的页面路径是/posts/{postId}
.这是我正在try 使用的代码
'use client'
async function fetchOnePost() {
// need to access URL path or param `{postId}` here
}
export default async function Page() {
const postData = await fetchOnePost();
return(<>....</>);
}
这是我的目录 struct ,指向该文件
app/
- posts/
- [postId]/
- page.js
基本上,我想要与Pages目录(/Pages/post/[postID].js)中使用的以下代码相同的应用程序目录代码:
export async function getServerSideProps(context) {
const { postId } = context.query;
const something = somthingDoneWithPostId(postId)
return { props: { something } };
}