[英]nextjs tab click reload same page
我有一個 Next.js 頁面/product
當我在/product
product
時,我單擊頂部橫幅(導航欄)上的產品(到 /product),我想在/product
頁面中獲取刷新頁面。
如何在同一頁面刷新?
例如,在我的頂部導航欄中,我有三個不同的鏈接路由器
當我在product
頁面並再次單擊產品鏈接時,但我想再次刷新整個頁面。
我試過下面的代碼對我來說不是解決方案
<a onClick={()=>router.push('/product')} >product</a>
您可以像這樣使用 router.reload() 函數:
import { useRouter } from 'next/router' export default function Page() { const router = useRouter() return ( <button type="button" onClick={() => router.reload()}> Click here to reload </button> ) }
你可以使用 javascript 函數-
window.href.reload()
這將重新加載頁面。 如果您正在使用 nextjs/reactjs,您可以在一些承諾和條件下使用它。希望您能得到答案。 如果您仍然面臨問題,請告訴我,我會幫助您。 謝謝
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.