I am trying to build a Laravel 5.5 + VueJs multi page app. I do not want to use SPA (Single Page Application) approach to make it seem to be a multi page app.
This is the case with the registration page at the URL /register
. With the command php artisan make:auth
I get the registration related files. The scenarios is :
In web.php
, I have :
Auth::routes();
In app.js
, I have :
window.Vue = require('vue');
const app = new Vue({
el: '#app',
components: {
Register: require('./components/Register.vue')
}
});
My layout.blade.php
resides within resources/views/
folder and has the following content :
<div id="app">
<?php
var_dump($component);
?>
@if (isset($component))
<component :is={{ $component }} >
@endif
@yield('content')
@if (isset($component))
</component>
@endif
</div>
The register.blade.php
file has the content :
@extends('layout', ['component' => 'Register'])
@section('content')
@endsection
Register.vue
stays inside resources/js/components/
and has the following content :
<template>
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">Example Component</div>
<div class="panel-body">
I'm an example component!
</div>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
mounted() {
console.log('Register Component mounted.')
}
}
</script>
So my intended work flow is: first the register.blade.php
will be called that inherits layout.blade.php
and sends as data the Register
component which is supposed to be rendered there.
I myself also do not know how the register.blade.php
will have the component Register
as parameter in the data at the line :
@extends('layout', ['component' => 'Register'])
And while viewing the page source, I even do not see the app.js
file being included in the page.
Of course, I run the npm run dev
command before testing the page every time.
Question 1 : What is wrong with the approach outlined above ? What should be the proper way however ?
EDIT:
My webpack.mix.js
has:
let mix = require('laravel-mix');
mix.js('resources/assets/js/app.js', 'public/js')
.styles([
'resources/assets/css/style.css'
], 'public/css/style.css')
;
mix.options({
extractVueStyles: 'public/css/vue-style.css'
});
EDIT2:
In the page, I see no content from the Register
component . I forgot to mention it before.
EDIT3: Question 2: Is Laravel+VueJs combination not meant for MPA (multi page application) in true sense of the term ?