boisterouslobster
boisterouslobster

Reputation: 1293

Vue-router not loading URL typed into browser

I have a Laravel 5.3 project utilizing Vue-router. I am using the <router-view></router-view> tags in a template (home.blade.php).

The only problem I am running into is that I can't seem to get the views by typing the URL into the router. It only works if I use router-link in my blade files.

Here is my main JS file where I implement the router:

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

Vue.use(VueRouter);
Vue.use(require('vue-resource'));

Vue.http.headers.common['X-CSRF-TOKEN'] = $('meta[name="csrf-token"]').attr('content');

Vue.component(
    'passport-clients',
    require('./components/passport/Clients.vue')
);

Vue.component(
    'passport-authorized-clients',
    require('./components/passport/AuthorizedClients.vue')
);

Vue.component(
    'passport-personal-access-tokens',
    require('./components/passport/PersonalAccessTokens.vue')
);

const routes = [
  { path: '/view1', component: require('./components/view1.vue')},
  { path: '/view2', component: require('./components/view2.vue')},
  { path: '/view3', component: require('./components/view3.vue')}
]

const router = new VueRouter({
  routes: routes,
})

const app = new Vue({
  router
}).$mount('#app')

My web.php file:

<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

//All the authentication routes
Auth::routes();

//Only routing needed for Laravel
Route::get('/{catchall?}', ['as' => 'start', 'middleware' => 'auth', function() {
    return view('home');
}])->where('catchall', '.*');

Any idea why it may be doing this?

Upvotes: 3

Views: 3755

Answers (1)

Matthias Wei&#223;
Matthias Wei&#223;

Reputation: 508

Have you tried setting history: true inside the new VueRouter, you don't need to use hash-URLs if you have a backend.

Upvotes: 3

Related Questions