如何在Next.js中強制重新加載頁面

在組件中,您可以使用useRouter鉤子: import { useRouter } from 'next/router' //... const router = useRouter() router.reload(window.location.pathname) 有時無法使用此方法,例如在非React組件中,例如在實用函數中。在這種情況下,您可以這樣做: import Router from 'next/router' Router.reload(window.location.pathname)