I have a Laravel App and I'm trying to add a vuejs form. The form has 3 differents steps so I want to use vuejs nested routes.
Problem is the parent component is called 2 times.
OnboardingForm.vue
: parent view, calling child components.
<template>
<div class="steps-container">
<div class="container">
<div class="step-progress">
Current step x {{ current_step }}
</div>
<router-view v-on:setStep="setStep"></router-view>
</div>
</div>
</template>
<script>
export default {
data() {
return {
current_step: null
}
},
methods: {
setStep(step) {
this.current_step = step;
},
}
}
</script>
The router view is working fine but the <div class="steps-container">
is rendered 2 times :
<div class="steps-container">
<div class="container">
<div class="step-progress">
Current step
</div>
<div class="steps-container">
<div class="container">
<div class="step-progress">
Current step from-component-1
</div>
<!-- Then the child component is successfully rendered -->
<div class="content-of-component">Component 1</div>
</div>
</div>
</div>
</div>
Associated files
Laravel route calling Controller web.php
Route::get('/onboarding/{any?}', [App\Http\Controllers\FormController::class, 'onboarding']);
Note this controller is only returning the blade file view('onboarding')
. Also onboarding.blade.php
is calling my main component <OnboardingForm>
VueJS Routes
const router = new VueRouter({
mode: 'history',
routes: [
{
path: '/onboarding',
component: OnboardingForm,
children: [
{
path: 'step1',
component: Component1
},
{
path: 'step2',
component: Component2
}
]
},
],
});
I am maybe wrong using both VueJS and Laravel routing system together.