Vue.js - How to add multiple layout in vuejs? Vue.js - How to add multiple layout in vuejs? vue.js vue.js

Vue.js - How to add multiple layout in vuejs?


I have played around with this before and the way I did it was to have alternative layouts that switch depending on a route meta field...

So when you define a route, you can add a meta field:

path: '/admin-panel/reports',          component: Reports,         name:'Reports',        meta: { template: 'admin' }

Then you need to check routes as they change. The easiest way to do this is in a global navigation guard (like the example has on their page). If it detects it's an admin page, it changes a Vuex property which will then switch which template you're using.

I will say that in the end I stopped using this method and wrapped all of my pages with wrapper components (admin/user/etc) so I could control everything from Vue itself. This was mainly due to Vue Router's limitations around waiting for a user to be authenticated though so that may not be an issue for you.