你要注意,next是分为纯静态渲染和SSR服务端渲染你使用getStaticProps是开启纯静态渲染,是无法获得动态的路由参数进行解析,除非你使用了动态路径解析。像你的需求你,需要将数据获取放到getServerSideProps中,而不要使用getStaticProps。这样你可以从中获得context,进而取得路径参数: export async function getServerSideProps(context) { console.log(context) //here,you can fetch data by context.query return { props: { query:context.query }, // will be passed to the page component as props } }
你要注意,next是分为纯静态渲染和SSR服务端渲染
你使用
getStaticProps
是开启纯静态渲染,是无法获得动态的路由参数进行解析,除非你使用了动态路径解析。像你的需求你,需要将数据获取放到
getServerSideProps
中,而不要使用getStaticProps
。这样你可以从中获得context,进而取得路径参数: