Solution: Configure Layouts for a Dashboard Site
Here’s the solution for how to configure layouts for a dashboard site.
We'll cover the following
Solution
Your task was to add routes for the dashboard and login pages and to modify the src/layout/Layout.vue
component to provide a layout
component based on the meta.layout
value specified in the routes. Here are the changes required:
For the src/router/index.js
file:
- Import
Dashboard
andLogin
components. - Add routes for the imported components.
- The
Dashboard
route should includemeta: { layout: ‘dashboard’ }
. - The
Login
route should includemeta: { layout: ‘auth’ }
.
For the src/layout/Layout.vue
file:
- Create a
LayoutComponentMap
that mapslayout
components todashboard
andauth
values that are provided through themeta
route config. - Create a computed prop called
layout
that returns alayout
component from theLayoutComponentsMap
by accessing the route meta layout information. TheDashboardLayout
component should be returned by default if there’s no layoutmeta
information.
Let’s run the widget below to understand how the solution above works.
Note: The code below may take a while to run. When the server starts, go to the app URL, and see the output.
Get hands-on with 1400+ tech skills courses.