【发布时间】:2023-03-03 20:57:01
【问题描述】:
我在我的项目中使用 nextJS SSR。现在,当我尝试使用以下代码获取页面参数时,它显示未定义。
function About() {
const router = useRouter();
const { plan_id } = router.query;
console.log(plan_id)
}
export default About;
当页面从其他页面路由时它可以工作(没有使用“next/link”重新加载页面)但是当我刷新页面时它不起作用。有人可以帮忙吗?
【问题讨论】:
-
原因是Next如何处理自动静态优化页面。请参阅nextjs.org/docs/routing/dynamic-routes#caveats 和 useSWR 的好例子:github.com/vercel/next.js/discussions/15952
标签: next.js server-side-rendering dynamic-routing next-router