reload()

The reload() function enables you to reload the page. The difference with window.location.reload is that reload() is much faster as it uses Vike's Client Router.

reload() works only with Client Routing. If you use Server Routing, then do window.location.reload() instead.

The most common use case for reload() is to refresh the page when an authentication cookie is updated, see Tool Integration > Authentication.

// /components/Logout.jsx
 
import { reload } from 'vike/client/router'
 
function Logout() {
   return <button onClick={logout}>Logout</button>
}
async function logout() {
  // Removes the authentication cookie
  await fetch('/logout', { method: 'POST' })
  // Re-render the page to take into account the removed cookie
  await reload()
  // Reload is finished
}

It's the same as navigate(window.location.href) but it handles some edge cases.