英文:
browser back button crashes website NextJS 13 after router.push hard navigation (app directory)
问题
我有一个按钮,需要使用next/navigation中useRouter的push方法来在程序中更改路由。在使用Chrome中的返回按钮进行软导航时,一切正常,但在使用返回按钮进行硬导航时,网站变得无响应,使用了100%的CPU,并且关闭选项卡无效。我必须强制退出Chrome。
我已完全删除了可能会影响导航的任何中间件。我还在几年前找到了一些旧的GitHub问题,其中有类似的问题,但在其中找不到任何解决方案。
请有人看一下我的非常简单的代码库,其中使用了应用程序路由器吗?https://github.com/bztravis88/gifgrams
在AuthToggle组件中,有一个使用router.push使返回按钮起作用的示例,该组件在登录和注册路由之间切换。一个出现此问题的router.push示例是从/到/account进行硬导航。
这是我使用next js的第一个重要项目,所以我可能在误用一些东西,感激任何帮助!
英文:
I have a button that needs to programatically change routes using the push method of useRouter from next/navigation. On soft navigation using the back button in Chrome works fine, but on hard navigation using the back button makes the site unresponsive, uses 100% cpu, and closing the tab doesn't work. I have to force quit Chrome.
I've completely removed any middleware that may have been affecting navigation. I also found some old github issues from years ago with similar issues, but couldn't find any solutions in them.
Could someone please take a peak at my very simple codebase using the app router? https://github.com/bztravis88/gifgrams
An example of the back button working with router.push is in the AuthToggle component which switches between the signin and signup routes. An example of a router.push that has this issue is a hard navigation from / to /account
This is my first major project using next js, so I may be misusing things, would appreciate any help!
答案1
得分: 0
问题是您不能定义一个带有异步函数的客户端组件的page.js。
英文:
The issue was that you cannot define a page.js with a client component that is an async function.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论