Add custom body classes to the router file
This commit is contained in:
parent
624ad8ad86
commit
8d450f42b2
26
resources/js/router-app.js
vendored
26
resources/js/router-app.js
vendored
@ -22,4 +22,30 @@ const router = VueRouter.createRouter({
|
||||
routes,
|
||||
});
|
||||
|
||||
const classes = {
|
||||
'index': ['page-home'],
|
||||
};
|
||||
|
||||
router.afterEach((to, from, failure) => {
|
||||
if (!failure) {
|
||||
if (!!from && !!from.name) {
|
||||
if (Object.keys(classes).includes(from.name.toString())) {
|
||||
for (const className of classes[from.name.toString()]) {
|
||||
if (document.body.classList.contains(className)) {
|
||||
document.body.classList.remove(className);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!!to && !!to.name) {
|
||||
if (Object.keys(classes).includes(to.name.toString())) {
|
||||
for (const className of classes[to.name.toString()]) {
|
||||
document.body.classList.add(className);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
export default router
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
@extends('template.base')
|
||||
|
||||
@section('body-classes', 'page-home')
|
||||
@push('js')
|
||||
<script src="{{ asset('js/app.js') }}"></script>
|
||||
@endpush
|
||||
|
||||
@ -11,12 +11,11 @@
|
||||
@stack('style')
|
||||
</head>
|
||||
|
||||
<body class="@yield('body-classes')">
|
||||
<body>
|
||||
@section('body')
|
||||
<div id="app"></div>
|
||||
@show
|
||||
|
||||
<script src="{{ asset('js/app.js') }}"></script>
|
||||
@stack('js')
|
||||
</body>
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user