Answer the question
In order to leave comments, you need to log in
Why doesn't webpack find routes by const in vue-cli assembly, but only by import?
Switching from simple to webpack vue assembly
noticed a strange feature in routing
import index from '@/pages/HelloWorld' // работает
const index = require('../pages/HelloWorld.vue') // не работает
const router = new Router({
mode: 'history',
scrollBehavior,
routes: [
{ name: 'index', path: '/', component: index, meta: { scrollToTop: true } }
]
});
[Vue warn]: Failed to mount component: template or render function not defined.
found in
---> <Anonymous>
<Main> at src/main/main.vue
<Root>
Answer the question
In order to leave comments, you need to log in
First: why HelloWorld.vue extension at the end.
Second: try
const index = require('../pages/HelloWorld.vue')
const router = new Router({
mode: 'history',
scrollBehavior,
routes: [
{ name: 'index', path: '/', component: index.default, meta: { scrollToTop: true } }
]
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question