Reputation: 2893
I am trying to remove any blade templates from my Laravel project, so this includes the homepage. I have left myself app.blade.php
which contains the following
<!doctype html>
<html lang="{{ app()->getLocale() }}">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="csrf-token" content="{{ csrf_token() }}">
<title>My Website</title>
<link href="/css/app.css" rel="stylesheet">
</head>
<body>
<div id="app">
<Navigation></Navigation>
<div class="container">
<main>
<router-view></router-view>
</main>
</div>
</div>
<script type="text/javascript" src="js/app.js"></script>
</body>
</html>
So a Navigation Component and a router-view. I have installed the router package. Within web.php
I have:
Route::get('/{any}', function(){
return view('layouts.app');
})->where('any', '.*');
Navigation.vue
is simple:
<template>
<div>
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<router-link to="/" tag="a" class="nav-link" active-class="active" exact>
<i class="nav-icon fas fa-tachometer-alt"></i>
<p>
Website Name
</p>
</router-link>
</div>
<ul class="nav navbar-nav">
<router-link to="/dashboard" tag="a" class="nav-link" active-class="active" exact>
<i class="nav-icon fas fa-tachometer-alt"></i>
<p>
Dashboards
</p>
</router-link>
</ul>
</div>
</nav>
</div>
</template>
<script>
export default {}
</script>
I also have a couple of basic components: App.vue
and Dashboard.vue
that contain basic templates. And then in app.js
I have:
require('./bootstrap');
window.Vue = require('vue');
import VueRouter from 'vue-router';
Vue.use(VueRouter);
import Navigation from './components/Navigation';
let routes = [
{ path: '/', component: require('./components/App.vue').default },
{ path: '/dashboard', component: require('./components/Dashboard.vue').default }
];
const router = new VueRouter({
mode: 'history',
routes
});
const app = new Vue({
el: '#app',
components: { Navigation },
router
});
So when I visit my localhost:8000
I see a mostly empty page besides the navigation, as to be expected. However, when I click on the link, the content of a sample component is not being displayed, even though the url is changing. For example, Dashboard
component is:
<template>
<div>
<main>
<h1>This is a dashboard</h1>
</main>
</div>
</template>
<script>
export default {}
</script>
Is there any reason within my setup why it is not displaying the content by clicking the navigation?
Upvotes: 1
Views: 52
Reputation: 10086
Using require(...).default
is required by vue-loader@15
which included in laravel-mix@4
. If you're using previous versions of laravel-mix
(as it seems) you should not add .default
:
let routes = [
{ path: '/', component: require('./components/App.vue') },
{ path: '/dashboard', component: require('./components/Dashboard.vue') }
];
Upvotes: 2