Answer the question
In order to leave comments, you need to log in
Lazy loading in Nuxt?
I am using plugin "@nuxtjs/router": "^1.4.0"
It doesn't work like this
import Vue from 'vue'
import Router from 'vue-router'
import paths from './routes/paths'
Vue.use(Router)
function route (path, view, name, meta) {
return {
name: name || view,
path,
meta,
component: (resovle) => import(`~/pages/${view}.vue`).then(resovle)
}
}
export function createRouter() {
return new Router({
mode: 'history',
routes: paths.map(path => route(path.path, path.view, path.name, path.meta)).concat([{ path: "*", redirect: "/" }])
})
}
import Vue from 'vue'
import Router from 'vue-router'
import Index from '~/pages/index.vue'
Vue.use(Router)
function route (path, view, name, meta) {
return {
name: name || view,
path,
meta,
component: Index
}
}
export function createRouter() {
return new Router({
mode: 'history',
routes: paths.map(path => route(path.path, path.view, path.name, path.meta)).concat([{ path: "*", redirect: "/" }])
})
}
component: (resovle) => import(`~/pages/${view}.vue`).then(resovle)
Answer the question
In order to leave comments, you need to log in
Attention!
Correct solution!
import Vue from 'vue'
import Router from 'vue-router'
import paths from './routes/paths'
Vue.use(Router)
function route (path, view, name, meta) {
return {
name: name || view,
path,
meta,
component: () => import(`~/pages/${view}.vue`).then(m => m.default || m) // здесь гребаный компонент
}
}
export function createRouter() {
return new Router({
mode: 'history',
routes: paths.map(path => route(path.path, path.view, path.name, path.meta)).concat([{ path: "*", redirect: "/" }])
})
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question