empty page showing (only "@routes" text comes out) when using Laravel8 + Inertia/vue.js together

this is my webpack.mix.js const mix = require(‘laravel-mix’); /* |————————————————————————– | Mix Asset Management |————————————————————————– … Read more empty page showing (only "@routes" text comes out) when using Laravel8 + Inertia/vue.js together

this is my webpack.mix.js

const mix = require('laravel-mix');

/*
 |--------------------------------------------------------------------------
 | Mix Asset Management
 |--------------------------------------------------------------------------
 |
 | Mix provides a clean, fluent API for defining some Webpack build steps
 | for your Laravel applications. By default, we are compiling the CSS
 | file for the application as well as bundling up all the JS files.
 |
 */

mix.js('resources/js/app.js', 'public/js').vue()
    .postCss('resources/css/app.css', 'public/css', [
        require('postcss-import'),
        require('tailwindcss'),
    ])
    .webpackConfig(require('./webpack.config'));

if (mix.inProduction()) {
    mix.version();
}

this is my app.blade.php

<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title inertia>{{ config('app.name', 'Laravel') }}</title>

    <!-- Fonts -->
    <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Nunito:[email protected];600;700&display=swap">

    <!-- Styles -->
    <link rel="stylesheet" href="{{ mix('css/app.css') }}">

    <!-- Scripts -->
    @routes
    <script src="{{ mix('js/app.js') }}" defer></script>
</head>

<body class="font-sans antialiased">
    @inertia

    @env('local')
    <script src="http://localhost:3000/browser-sync/browser-sync-client.js"></script>
    @endenv
</body>

</html>

this is my web.php

<?php

use AppHttpControllersGoogleAuthController;
use AppHttpControllersKakaoAuthController;
use IlluminateSupportFacadesRoute;
use InertiaInertia;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/asdasd', function () {
    return Inertia::render('Newpop');
});


Route::get('/', function () {
    return view('welcome');
});

Route::post('/', function () {
    return view('welcome');
});


Route::middleware(['auth:sanctum', 'verified'])->get('/dashboard', function () {
    return view('dashboard');
})->name('dashboard');


Route::get('/kakao/login', [KakaoAuthController::class, 'redirect'])->name('kakao.login');

Route::get('/kakao/callback', [KakaoAuthController::class, 'callback']);

Route::get('/github/login', [GithubAuthController::class, 'redirect'])->name('github.login');

Route::get('/github/callback', [GithubAuthController::class, 'callback']);


Route::get('/google/login', [GoogleAuthController::class, 'redirect'])->name('google.login');


Route::get('/google/callback', [GoogleAuthController::class, 'callback']);

this is my Newpop.vue (it is in js/Pages folder)

<template>
  <div>asdasddsdadzz</div>
</template>
<script>
export default {};
</script>

this is my app.js

/**
 * First we will load all of this project's JavaScript dependencies which
 * includes Vue and other libraries. It is a great starting point when
 * building robust, powerful web applications using Vue and Laravel.
 */

require('./bootstrap');

window.Vue = require('vue').default;

import {
    InertiaApp
} from '@inertiajs/inertia-vue'

Vue.use(InertiaApp)



new Vue({
    render: h => h(InertiaApp, {
        props: {
            initialPage: JSON.parse(app.dataset.page),
            resolveComponent: name => import(`./Pages/${name}`).then(module => module.default),
        },
    }),
}).$mount(app)
/**
 * The following block of code may be used to automatically register your
 * Vue components. It will recursively scan this directory for the Vue
 * components and automatically register them with their "basename".
 *
 * Eg. ./components/ExampleComponent.vue -> <example-component></example-component>
 */

// const files = require.context('./', true, /.vue$/i)
// files.keys().map(key => Vue.component(key.split('/').pop().split('.')[0], files(key).default))

Vue.component('example-component', require('./components/ExampleComponent.vue').default);
Vue.component('example-two', require('./components/ExampleTwo.vue').default);
Vue.component('hu-hu', require('./components/HuHu.vue').default);

/**
 * Next, we will create a fresh Vue application instance and attach it to
 * the page. Then, you may begin adding components to this application
 * or customize the JavaScript scaffolding to fit your unique needs.
 */

const app = new Vue({
    el: '#app',
});


// require('./bootstrap');

import Alpine from 'alpinejs';

window.Alpine = Alpine;

Alpine.start();

import "tailwindcss/tailwind.css"
import {
    InertiaProgress
} from '@inertiajs/progress'

createInertiaApp({
    resolve: name => import(`./Pages/${name}`),
    setup({
        el,
        App,
        props
    }) {
        new Vue({
            render: h => h(App, props),
        }).$mount(el)
    },
})

InertiaProgress.init()

enter image description here

when i starts php artisan serve,

my page shows only @routes.
i had changed app.js or webpack.mix.js like inertia documentation but it doesn’t work.

my other vue pages (not using inertia, using js fronend scaffolding) works well.

how can i use inertia component in my project?

Source: Vue – Stack Overflow



Leave a Reply

Your email address will not be published. Required fields are marked *