Search code examples
laravelvue.jsinertiajslaravel-jetstream

Route to vue file from Laravel Jetstream Inertia


I'm trying to setup a route inside Laravel Jetstream using Inertia. The route should be /bloglist.

the vue file is located in /resources/js/Blog/BlogList.vue

the route I am using is: Route::inertia('/bloglist', 'BlogList');

When I open the route I get a blank page and an error

Unhandled Promise Rejection: Error: Cannot find module './BlogList.vue'

What am I doing wrong?


Solution

  • The resolveComponent is set in the app.js. I don't believe it can be changed per route. You can, however, add resources/js/Pages/Blog/BlogList.vue and call it with

    Route::inertia('/bloglist', 'Blog/BlogList');
    

    Example app.js

    new Vue({
        render: (h) =>
            h(InertiaApp, {
                props: {
                    initialPage: JSON.parse(app.dataset.page),
                    resolveComponent: (name) => require(`./Pages/${name}`).default,
                },
            }),
    }).$mount(app);