1

I would like to use nwidart/laravel-modules and inertia together. The problem I'm having is that my Index.vue that is in my Users module isn't showing up and there is no errors.

When I have this line of code in my app.js

resolveComponent: (name) => require(`../../Modules/Users/Resources/assets/Pages/${name}`).default

then my Index.vue shows up, but when I try to loop through it so that I can make it dynamic nothing shows up and there is no errors

This is what I have in my app.js at the moment

require('./bootstrap');

require('moment');

import Vue from 'vue';

import { InertiaApp } from '@inertiajs/inertia-vue';
import { InertiaForm } from 'laravel-jetstream';
import PortalVue from 'portal-vue';

Vue.mixin({ methods: { route } });
Vue.use(InertiaApp);
Vue.use(InertiaForm);
Vue.use(PortalVue);

const app = document.getElementById('app');

const modulesJson = require("../../modules_statuses.json");
var modulesObject = Object.keys(modulesJson);

new Vue({
    render: (h) =>
        h(InertiaApp, {
            props: {
                initialPage: JSON.parse(app.dataset.page),
                resolveComponent: (name) => {
            // LOOP IS HERE
                    for(let i = 0; i < modulesObject.length; i++){
                        require('../../Modules/'+modulesObject[i]+'/Resources/assets/Pages/'+name).default
                    }
                }
            },
        }),
}).$mount(app);

1 Answer 1

1

Write the path of a file in your module when you want to run it through inertia. Then put a condition in the app.js file that if it is sent through the module, this code will be executed, otherwise it will return to the desired pages in the folder pages. Like the following code:

Route::get('test',function () {
    return \Inertia\Inertia::render('modules/Faq/resources/js/Pages/Admin/Index');
});
createInertiaApp({
   title: (title) => `${title} - ${appName}`,
   resolve: (name) => name.toString().indexOf('modules') > -1 ? require(`../../${name}.vue`) : require(`./Pages/${name}.vue`),
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.