Search code examples
vue.jsvue-routervue-loader

pass router params to component object


I have view and I want to load svg based on router params, I have installed vue-loader and it is working if I hard code it.

<template>
<div>
  <suit/>
</div>
</template>

<script>
export default {
  components:{

    suit: ()=>import('../assets/svg/'+Param+'.svg')
  }
}
</script>

<style>
</style>

This is what I have. Instead of Param I want to get this.route.params, but when I try this I get undefined which is logical because components wrapper is object. Is there a way to pass a variable here or must I redo the whole thing?


Solution

  • Instead of this.route.params, within a component you should be using this.$route.params. Vue Router Docs.