[Vuejs]-Why can't I use require in vue-router routes.js?

-1👍

**import and require work differently see the link bellow there are good documentation about the topic. **
es6 features
and require how Actually Works
**see the document how node js work under the hood how module.export work what is the nodejs design pattern (how node js wrap our code within Immediately invoked function expression and pass code into v8 engine)

you can simply midify your routes.js file

component:() => import(‘./components/Register.vue’) or
component: require(‘./components/Login.vue’).default

both will work

[{ path: ‘/’, component:() => import(‘./components/Register.vue’) },
{ path: ‘/register’, component: require(‘./components/Login.vue’).default }];

Leave a comment