From a64b92866b66521cacb6322d0bcbff52c65b7520 Mon Sep 17 00:00:00 2001 From: anil kumar thakur Date: Wed, 24 Apr 2024 00:31:32 +0545 Subject: [PATCH] ssr.js layout fixes --- resources/js/ssr.js | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/resources/js/ssr.js b/resources/js/ssr.js index b4091fae..012ceb2b 100644 --- a/resources/js/ssr.js +++ b/resources/js/ssr.js @@ -2,18 +2,24 @@ import { createSSRApp, h } from 'vue' import { renderToString } from '@vue/server-renderer' import { createInertiaApp } from '@inertiajs/vue3' import createServer from '@inertiajs/vue3/server' +import { resolvePageComponent } from 'laravel-vite-plugin/inertia-helpers' +import layout from '@/Shared/Layout.vue' createServer((page) => createInertiaApp({ - page, - render: renderToString, - resolve: name => { - const pages = import.meta.glob('./Pages/**/*.vue', { eager: true }) - return pages[`./Pages/${name}.vue`] - }, - title: title => title ? `${title} - Ping CRM` : 'Ping CRM', - setup({ app, props, plugin }) { - return createSSRApp({ - render: () => h(app, props), - }).use(plugin) - }, + page, + render: renderToString, + resolve: async (name) => { + const page = await resolvePageComponent(`./Pages/${name}.vue`, import.meta.glob('./Pages/**/*.vue')) + const pageWithoutLayout = ['Auth/Login', 'Auth/TwoFactor'] + if (!pageWithoutLayout.includes(name)) { + page.default.layout ??= layout + } + return page + }, + title: title => title ? `${title} - Ping CRM` : 'Ping CRM', + setup({ app, props, plugin }) { + return createSSRApp({ + render: () => h(app, props), + }).use(plugin) + }, }))