changing page layout assignment to work with Vite now

This commit is contained in:
Brian 2022-09-27 11:12:05 -06:00
parent 606899494c
commit 5f87596b2f
Signed by: brian
GPG Key ID: DE1A5390A3B84CD8

View File

@ -3,8 +3,13 @@ require("./bootstrap");
import { createApp, h } from 'vue'; import { createApp, h } from 'vue';
import { createInertiaApp } from '@inertiajs/inertia-vue3'; import { createInertiaApp } from '@inertiajs/inertia-vue3';
import { InertiaProgress } from '@inertiajs/progress'; import { InertiaProgress } from '@inertiajs/progress';
import { resolvePageComponent } from 'laravel-vite-plugin/inertia-helpers';
import { ZiggyVue } from '../../vendor/tightenco/ziggy/dist/vue.m'; import { ZiggyVue } from '../../vendor/tightenco/ziggy/dist/vue.m';
import Notifications from 'notiwind'; import Notifications from 'notiwind';
import AppLayout from './Layouts/AppLayout.vue';
import AuthLayout from './Layouts/AuthLayout.vue';
import BaseLayout from './Layouts/BaseLayout.vue';
import GuestLayout from './Layouts/GuestLayout.vue';
const appName = window.document.getElementsByTagName('title')[0]?.innerText || 'Laravel'; const appName = window.document.getElementsByTagName('title')[0]?.innerText || 'Laravel';
@ -14,7 +19,25 @@ window.genUid = function () {
createInertiaApp({ createInertiaApp({
title: (title) => `${title} - ${appName}`, title: (title) => `${title} - ${appName}`,
resolve: (name) => require(`./Pages/${name}.vue`), resolve: (name) => {
const page = resolvePageComponent(`./Pages/${name}.vue`, import.meta.glob('./Pages/**/*.vue'));
page.then((module) => {
if (module.default.layout === undefined) {
if (name.startsWith('Auth/')) {
module.default.layout = AuthLayout;
} else if (name.startsWith('Dashboard/') || name.startsWith('Profile/')) {
module.default.layout = AppLayout;
} else if (name.startsWith('Guest/')) {
module.default.layout = GuestLayout;
} else if (!name.startsWith('Components/') && !name.startsWith('Jetstream/') && !name.startsWith('Icons/') && !name.startsWith('Layouts/') && !name.includes('Partials')) {
module.default.layout = BaseLayout;
}
}
});
return page;
},
setup({ el, app, props, plugin }) { setup({ el, app, props, plugin }) {
return createApp({ render: () => h(app, props) }) return createApp({ render: () => h(app, props) })
.use(plugin) .use(plugin)