0

I'm running into a problem where my Vue component isn't showing via router-view, there are no Vue warnings or errors in the console.

Here's the git: https://github.com/woottonn/fullstack

Here's my code:

web.php

<?php

Route::any('{any}', function(){
    return view('welcome');
})->where('any', '.*');

welcome.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>Full Stack Blog</title>
    </head>
    <body class="antialiased">
        <div id="app">
            <mainapp></mainapp>
        </div>
    <script src="{{mix('/js/app.js')}}"></script>
    </body>
</html>

app.js

require('./bootstrap');
import Vue from 'vue'
import router from './router'

Vue.component('mainapp', require('./components/mainapp.vue').default)
const app = new Vue({
    el: '#app',
    router
});

router.js

import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

import myFirstVuePage from './components/pages/myFirstVuePage'

const routes = [
    {
        path: '/my-new-vue-route',
        component: myFirstVuePage
    }
];

export default new Router({
    mode: 'history',
    routes
})

mainapp.vue

<template>
    <div>
        <h1>VUE Componenty</h1>
        <router-view></router-view>
    </div>
</template>

myFirstVuePage.vue

<template>
    <div>
        <h1>This is my first page...</h1>
    </div>
</template>

enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here

Am I missing obvious something here?

--- EDIT: Going directly to the URL (/my-new-vue-route) throws an error, so that's not working either. ---

1 Answer 1

1

In routes/web.php, add this:

Route::get('/{vue_capture?}', function () {
    return view('welcome');
})->where('vue_capture', '[\/\w\.-]*');

This helps the Laravel to capture URLs generated by Vue and is a solution for routing when history mode is set, as you seem to have.

export default new Router({
    mode: 'history',
    routes
})
3
  • Thanks for the input! I just tried this. All it does is throw me back to the welcome page. The "myFirstVuePage.vue" still doesn't show :( Commented Nov 19, 2021 at 13:27
  • @user3706091 if you use /#/my-new-vue-route url, does it show? if so, then it seems to be an issue with the history mode
    – PatricNox
    Commented Nov 20, 2021 at 23:25
  • It throws me back to the welcome page view which containts the "mainapp" vue. This is the only thing in my web routes file, I believed this is the code to tell laravel that vue is handling the routing, or am I wrong?: Route::any('{any}', function(){ return view('welcome'); })->where('any', '.*'); Commented Nov 22, 2021 at 8:29

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.