Default layout and code-splitting #1998
-
I've setup a default layout following the documentation for Vite. It's working perfectly. However, I now need to use the code-splitting option and I can't get the default layout to play nicely when using code-splitting. Is this possible? If so, can somebody please show how the resolve method should look when trying to combine the two? Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 3 replies
-
Sample code here: https://github.com/flivstack/flivstack/blob/main/resources/js/app.ts |
Beta Was this translation helpful? Give feedback.
-
There is a guide here for Vue, if that's is what you're after? :) |
Beta Was this translation helpful? Give feedback.
-
Hello! <script setup>
import { RouterView } from “vue-router”;
import DefaultLayout from “@/components/layout/DefaultLayout.vue”;
</script>
<template>
<DefaultLayout>
<RouterView />
</DefaultLayout>
</template> I put Layout.vue in the resources/js/Pages directory. In the resources/js/components/layout/partials directory I create the files that I then import into DefaultLayout.vue. |
Beta Was this translation helpful? Give feedback.
-
Thanks for all the suggestions, but I don't have any issue getting the default layout to work. My issue is that it stops working when trying to implement code-splitting, which is not covered by any of your suggestions. The
I can also also implement code-splitting (again, straight out of the Inertia docs), without the default layout:
Combining the two is when the problem starts:
This gives an error: |
Beta Was this translation helpful? Give feedback.
-
Ok. The problem you have occurs because the object 'page' you are trying to modify is 'undefined'. This happens if the import of the component has not been resolved correctly. resolve: async name => {
const pages = import.meta.glob('./Pages/**/*.vue', { eager: false });
let page = await pages[`./Pages/${name}.vue`]();
page.default.layout = name.startsWith('Auth/') ? undefined : AppLayout;
return page;
} That code should help you solve the problem. I hope it helps. |
Beta Was this translation helpful? Give feedback.
Ok. The problem you have occurs because the object 'page' you are trying to modify is 'undefined'. This happens if the import of the component has not been resolved correctly.
When you use 'eager: false', 'page' becomes a promise, and you need to wait for it to resolve before trying to access its properties. Here is a way to fix your code:
That code should help you solve the problem. I hope it helps.