On my application I have multiple layouts. They are separated in different folders. I would like to use different SCSS files for the layouts. However no matter what layout is in use (based on a prop on router meta), all the SCSS files are imported. This messes up the layouts because the styles got mixed. Is there a way of import only the SCSS related to the layout on use?
App.vue
<template>
<component :is="layout" />
</template>
<script>
import DefaultLayout from '@/layouts/default/DefaultLayout';
import PrimaryLayout from '@/layouts/primary/PrimaryLayout';
import SecondaryLayout from '@/layouts/secondary/SecondaryLayout';
export default {
components: {
DefaultLayout,
PrimaryLayout,
SecondaryLayout
},
data() {
return {
layout: null
}
},
watch: {
$route(to, from) {
document.title = to.meta.title;
this.layout = to.meta.layout || 'DefaultLayout';
}
}
};
</script>
src/layouts/primary/PrimaryLayout.vue
<template>
Html content here
<router-view />
</template>
<script>
export default {
name: 'PrimaryLayout'
}
</script>
<style lang="scss">
@import '@/assets/layouts/primary/scss/main.scss';
</style>
src/layouts/secondary/SecondaryLayout.vue
<template>
Different html content here
<router-view />
</template>
<script>
export default {
name: 'SecondaryLayout'
}
</script>
<style lang="scss">
@import '@/assets/layouts/secondary/scss/main.scss';
</style>
src/router/index.js
import { createRouter, createWebHistory } from 'vue-router';
const routes = [
{
path: '/login',
name: 'Login',
component: () => import('@/pages/auth/Login.vue'),
meta: {
layout: 'PrimaryLayout',
title: 'Auth Page'
}
},
{
path: '/admin',
name: 'Admin',
component: () => import('@/pages/admin/Admin.vue'),
children: [
{
path: '',
name: 'Dashboard',
component: () => import('@/pages/admin/Dashboard.vue'),
meta: {
layout: 'SecondaryLayout',
title: 'Admin | Home'
},
},
... other pages ...
]
}
]
Can aynone give me a help?