简体   繁体   中英

Vue-Router only showing base route using Laravel Blade?

I'm switching from routing with Laravel to using Vue-Router on my application, and I can only get the base route to load using Vue-Router. I've seperated the routes into two files, public and private using the example from this article: https://itnext.io/vue-router-99e334094362 . I'm new to Vue-Router, what am I doing wrong?

Here's my code:

main.blade.php :

<div id="app">
        <section>
            <!-- header menu -->
            <am-app-nav></am-app-nav>
        </section>
        <section>
            <router-view></router-view>
        </section>
        <section>
            <!-- Footer -->
            <am-footer></am-footer>
        </section>
    </div>

app.js :

window.Vue = require('vue')

import Vue from 'vue'
import VueRouter from 'vue-router'
import router from './router/index.js'

Vue.use(VueRouter)

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

router/index.js :

import Vue from 'vue'
import Router from 'vue-router'
import routes from './routes/index.js'
Vue.use(Router)

const router = new Router({
  mode: 'history',
  routes: [
    {
      path: '/',
      redirect: '/welcome',
    },
  ].concat(routes),
})

export default router

router/routes/index/js :

import publicRoutes from './public.js'
import privateRoutes from './private.js'

export default publicRoutes.concat(privateRoutes)

router/routes/private.js :

const routes = [
  {
    path: '/dashboard',
    component: require('../../views/admin/Dashboard').default,
  },
  {
    path: '/client-details',
    component: require('../../views/admin/ClientDetails').default,
  },
  { 
    path: '*', component: require('../../views/public/NotFound').default 
  },
]

export default routes.map((route) => {
  return { ...route, meta: { public: false } }
})

I needed to add this to web.php :

// SPA Route
Route::get('{any}', function () {
    return view('_layouts.main');
})->where('any', '.*');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM