Search code examples
javascripttypescriptvue.jsvuejs3vue-router

How to create a simple component inline?


I have a component that looks like this:

App.vue

<template>
  <RouterView />
</template>

I would like to not have a file for such a simple component. How would I go about creating such a component inline?

I tried the following and it works to some extend but the router-view is not being recognized as such:

defineComponent(() => () => h('router-view', {}))

Solution

  • import { RouterView } from 'vue-router'!
    
    defineComponent(() => () => h(RouterView, {}));