2023-12-30 05:29:53 +00:00
|
|
|
// https://vike.dev/onRenderClient
|
2024-01-25 02:07:26 +00:00
|
|
|
import { createApp } from './app.js';
|
2023-12-30 05:29:53 +00:00
|
|
|
|
|
|
|
// This onRenderClient() hook only supports SSR, see https://vike.dev/render-modes for how to modify onRenderClient()
|
|
|
|
// to support SPA
|
|
|
|
async function onRenderClient(pageContext) {
|
|
|
|
const { Page, pageProps } = pageContext;
|
2024-01-25 02:07:26 +00:00
|
|
|
|
|
|
|
if (!Page) {
|
|
|
|
throw new Error('Client-side render() hook expects pageContext.Page to be defined');
|
|
|
|
}
|
|
|
|
|
2023-12-30 05:29:53 +00:00
|
|
|
const app = createApp(Page, pageProps, pageContext);
|
2024-01-25 02:07:26 +00:00
|
|
|
|
2023-12-30 05:29:53 +00:00
|
|
|
app.mount('#app');
|
2024-03-19 02:17:19 +00:00
|
|
|
|
|
|
|
if (typeof window !== 'undefined') {
|
|
|
|
window.addEventListener('popstate', () => {
|
2024-03-19 19:50:50 +00:00
|
|
|
if (!window.location.hash) {
|
|
|
|
// force reload when back button is used
|
|
|
|
window.location.reload();
|
|
|
|
}
|
2024-03-19 02:17:19 +00:00
|
|
|
});
|
|
|
|
}
|
2023-12-30 05:29:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export { onRenderClient };
|