Skip to content

Instantly share code, notes, and snippets.

@Tattomoosa
Last active April 28, 2018 01:17
Show Gist options
  • Save Tattomoosa/f28f8c2d725682ddf519c5b9b3025b4e to your computer and use it in GitHub Desktop.
Save Tattomoosa/f28f8c2d725682ddf519c5b9b3025b4e to your computer and use it in GitHub Desktop.
Vue Router component that auto populates with links to every route
<!-- inspired by https://stackoverflow.com/questions/36120996/get-all-routes-in-a-vue-router/36128368 -->
<template>
<div>
<span v-for="route in routes" :key="route.name">
<router-link :to="route.path">{{ route.name }}</router-link>
</span>
</div>
</template>
<script>
export default {
name: 'Navigation-Menu',
created () {
// This dynamically grabs every route in router
this.$router.options.routes.forEach(route => {
this.routes.push({
name: route.name,
path: route.path
})
})
},
data () {
return {
routes: []
}
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment