I am currently working on a website using Laravel and Vue.js. I require two separate sections for the site:
- Site: https://www.example.com
- Admin: https://www.example.com/admin
Within the resource/js/app.js file, I have included the main components as follows:
require('./bootstrap');
import VueRouter from "vue-router";
import Frontend from "./frontend/Index";
import Admin from "./backend/Index";
import router from "./routes";
window.Vue = require('vue');
Vue.use(VueRouter);
const app = new Vue({
el: '#app',
router,
components: {
"index": Frontend,
"admin": Admin,
}
});
In the routes.js file:
import VueRouter from 'vue-router';
import Home from './frontend/Dashboard';
import Authors from './frontend/authors/Authors';
import Admin from './backend/Dashboard';
const routes = [
{
path: "/",
component: Home,
name: "home",
},
{
path: "/authors",
component: Authors,
name: "authors",
},
{
path: "/admin",
component: Admin,
name: "admin",
}
]
const router = new VueRouter({
routes,
mode: "history",
})
export default router;
A challenge I am facing is when accessing https://www.example.com/authors via the browser it loads correctly with the desired template. However, if I navigate to it from the admin section, it loads in the Admin template.
The organization of files is structured as below:
- resources
- js
- backend
- Index.vue
- Dashboard.vue
- frontend
- Index.vue
- Dashboard.vue
- Authors
- Authors.vue
When on www.example.com, the main layout loaded is from resource/js/frontend/Index.vue.
Conversely, when on www.example.com/admin, the main layout loaded is from resource/js/backend/Index.vue
If I directly use the URL via the browser, the main layouts load correctly. However, if I utilize
<router-link class="btn nav-button" :to="{name: 'authors'}">Author</router-link>
from the admin section, the authors component gets loaded within the admin layout instead of the frontend layout.