I am creating an application with laravel backend and vue in frontend. I need 3 separate SPA entry routes (each for guest users, registered users and admin users) in the web.php file like this:
Route::get('/', function() {
return view('guest.index');
});
Route::any('/admin/{any}', function () {
return view('dashboard.admin.dashboard');
})->where(['any', '.*']);
Route::get('/{any}', function() {
return view('user.dashboard');
})->where('any', '((?!(api)).)*');
My app.js file looks like this:
require('./bootstrap');
import Vue from 'vue'
import router from './routes/index'
export const eventBus = new Vue();
// using vue-router
import VueRouter from 'vue-router'
import { routes } from "./routes";
import axios from 'axios';
Vue.use(VueRouter)
import Guest from './pages/Guest.vue';
// Entry point for Users
import Dashboard from './pages/Dashboard.vue';
// Admin pages
import Admin from './components/admin/vuelayouts/Admin.vue';
if (document.getElementById('dashboard')) {
const dashboard = new Vue({
el: '#dashboard',
components: {
Dashboard
},
router
});
}
if (document.getElementById('guest')) {
const guest = new Vue({
el: '#guest',
components: {
Guest
},
router
});
}
if (document.getElementById('admin')) {
Vue.component('admin', Admin);
Vue.component('paginate', Paginate);
Vue.use(VueFlashMessage);
const dashboard = new Vue({
el: '#adminapp',
components: {
},
router
});
}
This doesn't work so far. I can only access the guest and user pages but unable to reach the admin page. Is using the if-blocks to access the different routes, the best approach? Any ideas please?
url('/#/admin')
from your controller? Your Vue code should not have to repeat itself like that. And I see that you imported your routes but you never attached them to your router. You should read the docs on how to do this. – parker_codes