[Vuejs]-Vue Router + Laravel: Reloading a page without a 404 and passing in a route varable

0👍

Well, as far I can see, your approach was good. You are capturing all GET requests, and passing them to your Blade view.

My suggestion:

  • Cleaner route:
    Route::get('/{any}', 'YourController@index')->where('any', '.*');

Your app.js (main JS file should look something like this):

import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

import App from './views/App'
import About from './views/About'
import Home from './views/Home'

const router = new VueRouter({
    mode: 'history',
    routes: [
        {
            path: '/',
            name: 'home',
            component: Home
        },
        {
            path: '/about',
            name: 'about',
            component: About,
        },
    ],
});

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

With all this configuration and your router-view, you should be fine.

Leave a comment