⚠
vite-plugin-ssr has been renamed Vike, see migration guide.

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 vite-plugin-ssr's Client Router.

navigate() 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 Guides > Authentication.

// /components/Logout.jsx

import { reload } from 'vite-plugin-ssr/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.