Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

question lazy load #6

Closed
javialon26 opened this issue Sep 29, 2017 · 7 comments
Closed

question lazy load #6

javialon26 opened this issue Sep 29, 2017 · 7 comments

Comments

@javialon26
Copy link

javialon26 commented Sep 29, 2017

hello @Atinux with this module are the routes still lazy?

This question is available on Nuxt.js community (#c2)
@Atinux
Copy link
Member

Atinux commented Oct 2, 2017

Hi @javialon26

Actually no, you have to do it manually, example:

import Vue from 'vue'
import Router from 'vue-router'

// lazy load the pages
const MyPage = () => import('~/components/my-page')

Vue.use(Router)

export function createRouter() {
  return new Router({
    mode: 'history',
    routes: [
      {
        path: '/',
        component: MyPage
      }
    ]
  })
}

@Atinux Atinux closed this as completed Oct 2, 2017
@javialon26
Copy link
Author

@Atinux i have an error with this config:

[Vue warn]: You are using the runtime-only build of Vue where the template compiler is not available. Either pre-compile the templates into render functions, or use the compiler-included build.
found in

--->
at .nuxt/components/nuxt.vue
at layouts/default.vue

[Vue warn]: The client-side rendered virtual DOM tree is not matching server-rendered content. This is likely caused by incorrect HTML markup, for example nesting block-level elements inside

, or missing . Bailing hydration and performing full client-side render.

this is my router.js

import Router from 'vue-router'

// import HomePage from '@/components/pages/index.vue'

const HomePage = () => import('@/components/pages/index.vue')
const HelpPage = () => import('@/components/pages/ayuda.vue')

Vue.use(Router)

export function createRouter () {
  return new Router({
    mode: 'history',
    routes: [
      {
        path: '/',
        name: 'home',
        component: HomePage
      },
      {
        path: '/ayuda',
        name: 'ayuda',
        component: HelpPage
      }
    ]
  })
}

thank you

@Atinux
Copy link
Member

Atinux commented Oct 3, 2017

@javialon26 Sorry I forgot something, try with:

import Router from 'vue-router'

// import HomePage from '@/components/pages/index.vue'

const HomePage = () => import('@/components/pages/index.vue').then(m => m.default || m)
const HelpPage = () => import('@/components/pages/ayuda.vue').then(m => m.default || m)

Vue.use(Router)

export function createRouter () {
  return new Router({
    mode: 'history',
    routes: [
      {
        path: '/',
        name: 'home',
        component: HomePage
      },
      {
        path: '/ayuda',
        name: 'ayuda',
        component: HelpPage
      }
    ]
  })
}

@javialon26
Copy link
Author

@Atinux work like a charm, thank you!

@sschadwick
Copy link

Ran into the same issue when attempting to customize code-splitting. Can confirm that the solution provided by @Atinux (.then(m => m.default || m)) works!

@ghost
Copy link

ghost commented Sep 13, 2018

This question has been resolved by @Atinux, see answer.

@ghost ghost added the cmty:status:resolved label Sep 13, 2018
@mrleblanc101
Copy link

Should this be documented somewhere in the doc ?
I had a (probably) the same issue but with a slightly different error message and @Atinux solution solved it.
render function or template not defined in component: anonymous

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants