如果这是一个 super 愚蠢的问题,我很抱歉,我是 Next.js 和 React.js 的初学者。
我有一些基本知识,在 Next.js 中,我们可以创建页面层次结构,xx_page.js 文件的路径将是该 js 文件的 url 路由,as described in the documentation .
例如,我的页面结构如下,
pages // a folder
| -- home // a folder
| | -- index.js // a file, the code for route "/home"
| -- sports // a folder
| | -- index.js // a file, the code for route "/home/sports"
| | -- football.js // a file, the code for "/home/sports/football"
假设当前页面位于“xxx.com/home/sports/football”路线,页面上有一个“返回”按钮,点击后要返回“xxx.com/home/”体育”。
我没能找到正确的方法来做到这一点,我通过 Google 找到的大部分内容都是返回上一页,而不是我想要的。
请给我一些关于如何在 Next.js 中执行此操作的帮助,谢谢!
最佳答案
“返回”没有正确的定义,所以你必须定义它。对于您的按钮,如果您执行以下操作
<Link href="/home/sports">
<a className="back">←</a>
</Link>
它的行为应该完全符合您的要求。
关于javascript - Next.js:如何从当前子页面转到父页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69510948/