-
-
Save steffen-wirth/fe8386036de8aa4936cda6cd5ce8053e to your computer and use it in GitHub Desktop.
Vue 2 - VueRouter - Simple Dynamic breadcrumbs + Microdata
This file contains 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 { | |
beforeRouteEnter(route, redirect, next) { | |
next(vm => { | |
vm.$http.get(`${API.BASE}/${API.PAGE}/${route.name}`).then((response) => { | |
vm.page = response.data.page; | |
vm.eventHub.$emit('update-breadcrumb', [ | |
{ | |
title: 'Home', | |
link: { | |
name: 'home.index' | |
} | |
}, { | |
title: vm.page.title, | |
link: { | |
name: vm.page.slug, | |
slug: null // optional slug goes here i.e. 1 would result in matching the route: /page/:slug, so it'll output /page/1 | |
} | |
} | |
]); | |
}); | |
}); | |
}, | |
} |
This file contains 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
// Somewhere in your app/bootstrap file, add a centralised event hub/container | |
/* ============ | |
* Vue Event Hub | |
* ============ | |
* | |
* Distribute to components using global mixin | |
* | |
* http://taha-sh.com/blog/understanding-components-communication-in-vue-20 | |
*/ | |
const eventHub = new Vue(); | |
Vue.mixin({ | |
data: function () { | |
return { | |
eventHub: eventHub | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment