Default route is not working with laravel and vue

1k Views Asked by At

I am creating a single page application using laravel and vue. it's not loading index component on page load.

web.php

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

Welcome.blade.php

<body>
    <div id="app">
    <router-view></router-view>      
    </div>
  <script src="{{asset('js/app.js')}}"></script>
</body>

router.js file

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

Vue.use(VueRouter)
const routes = [
{ path: '/', component: require('./components/IndexComponent.vue') },
{ path: '/login', component: require('./components/LoginComponent.vue') }
]

const router = new VueRouter({
routes:routes,
mode:'history' 
})
export default new VueRouter({router})

app.js file

require('./bootstrap');

window.Vue = require('vue');
import vuetify from './vuetify';
import router from './router';

import Index from './components/IndexComponent'; 
import Login from './components/LoginComponent'; 

var app = new Vue({
el: '#app',
router,
vuetify,
components: {
    'index-component':Index,
    'login-component':Login
}
});

Index Component (IndexComponent.vue)

<template>
  <router-link to="/" class="nav-item nav-link">Home</router-link>
                <router-link to="/login" class="nav-item nav-link">Login</router-link>
 <router-view></router-view>
 </template>
1

There are 1 best solutions below

0
On

I had the same problem. Open your project in chrome and press Ctrl + Shift + I (Open console). Now after the login you can see that there is a warning which says: No match for favicon.ico. To solve this problem you go to your routes file and define a redirect:

{
    path: '/favicon.ico',
    redirect: '/user/dashboard'
}