[Vuejs]-Conditional importing of components in Vue Router

3πŸ‘

βœ…

Is it somewhere documented that you can use a function for component?
Instead of a function you could use a getter:

import Mycomponent from '@/views/Mycomponent'
import MycomponentDifferent from '@/views/MycomponentDifferent'

{
  name: 'My component name',
  path: somepath,
  get component() {
    if(true) {
     console.log(Mycomponent) // You can see in console whole component
     return Mycomponent
    } else {
     return MycomponentDifferent
    }
  }
}
πŸ‘€Crackers

Leave a comment