Last active
September 3, 2020 19:38
-
-
Save daliborgogic/30398658b2e0518595f8773d36b2766f to your computer and use it in GitHub Desktop.
[POC] Dynamic component by current route
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<Component :is="is" /> | |
</template> | |
<script> | |
import layout from '@/helpers/layout' | |
const components = { | |
vBuilding: () => import('@/components/pages/Building.vue' /* webpackChunkName: `building` */), | |
vSeminaire: () => import('@/components/pages/Seminaire.vue' /* webpackChunkName: 'components/page/seminaire' */), | |
vCoaching: () => import('@/components/pages/Coaching.vue' /* webpackChunkName: 'components/page/coaching' */), | |
vDestination: () => import('@/components/pages/Destination.vue' /* webpackChunkName: 'components/page/destination' */), | |
vDefault: () => import('@/components/pages/Default.vue' /* webpackChunkName: 'components/page/default' */) | |
// ... | |
} | |
export default { | |
data: () => ({ | |
layout: 'Default' | |
}), | |
computed: { | |
is() { | |
return 'v' + layout(this.$route.params) | |
} | |
}, | |
components | |
} | |
</script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default params => { | |
const { page, slug = null } = params | |
if (page.startsWith('team-building-')) { | |
return 'Destination' | |
} else if (page.startsWith('animation-seminaire-')) { | |
return 'Destination' | |
} else if (page.startsWith('coaching-entreprise-')) { | |
return 'Destination' | |
} else if ('destinations-team-building' === page) { | |
return 'Building' | |
} else if ('animation-seminaire' === page) { | |
return 'Seminaire' | |
} else if ('coaching-entreprise' === page) { | |
return 'Coaching' | |
} else { | |
return 'Default' | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment