简体   繁体   中英

nextjs tab click reload same page

I have a Next.js page /product

When I'm on /product , and I click product on the top banner(navbar) (to /product), I wanna get refresh page in /product page.

how to refresh in the same page?

For example, in my top navbar I have three different link router

  • home
  • Product
  • ask

when i'm in product page and click product link again but i want to refresh whole page again.

i have tried this code down below was not solution for me

  <a onClick={()=>router.push('/product')} >product</a>

You can use router.reload() function like this:

 import { useRouter } from 'next/router' export default function Page() { const router = useRouter() return ( <button type="button" onClick={() => router.reload()}> Click here to reload </button> ) }

you can use javascript function-

window.href.reload()

this will reload the page. If you're using nextjs/reactjs you can use it with some promises and conditions.. Hope you'll get your answer. If you still facing issue, just lemme know, i will help you. Thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM