Skip to content
This repository was archived by the owner on Aug 27, 2020. It is now read-only.

Lazy load typescript component #20

Closed
fpoliquin opened this issue Apr 25, 2017 · 2 comments
Closed

Lazy load typescript component #20

fpoliquin opened this issue Apr 25, 2017 · 2 comments

Comments

@fpoliquin
Copy link

Hi,

I've been testing your template for a couple of days and so far it's been great except for this issue. Is there a way to lazy load a TypeScript component ?

See router doc

I've been trying using something like this:

AsyncModule.ts:

import Vue from 'vue'
import Component from 'vue-class-component'

@Component
export default class AsyncModule extends Vue {

    render(h) {
        return h('p', 'Hello')
    }
}

Router.ts

const AsyncModule = resolve => (require as any)(['components/AsyncModule'], resolve)

export default new Router({
    routes: [
        ...
        {
            path: '/routes',
            name: 'Routes',
            component: Routing,
            children: [
                {
                    path: 'asyncmodule',
                    name: 'AsyncModule',
                    component: AsyncModule
                }
            ]
        }]})

If I replace:

const AsyncModule = resolve => (require as any)(['components/AsyncModule'], resolve)

By

import AsyncModule from 'components/AsyncModule'

Everything works (except it is not lazy).

In the browser console, I can see this error:

[Vue warn]: Failed to mount component: template or render function not defined.

Thanks

@Toilal
Copy link
Owner

Toilal commented Apr 25, 2017

I don't use lazy component loading for now, so I can't really help sorry.

Maybe you could open an issue in vue-class-component project ?

@fpoliquin
Copy link
Author

Finally, I created this bug vue-router-1379

Thanks for your help.

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

No branches or pull requests

2 participants