Setting initial route fails when routes have dynamic import
See original GitHub issueDescribe the bug There is a test which shows that initialising a router can be done by pushing a path. We use dynamic imports to lazy load our routes. In combination, this results that the initial route is not set at all. https://github.com/testing-library/vue-testing-library/blob/d628f36b6122e629553d388a9c4953fc5cb2e1ab/src/__tests__/vue-router.js#L29-L31
To Reproduce Change the following line to
{path: '/about', component: () => import('./components/Router/About.vue')},
and run the tests. https://github.com/testing-library/vue-testing-library/blob/d628f36b6122e629553d388a9c4953fc5cb2e1ab/src/__tests__/vue-router.js#L10
Expected behavior I expected that to work right out of the box or with help of waitFor or something… But I did not manage to get it working.
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (4 by maintainers)
Top Results From Across the Web
vue + nuxt: dynamic import of route pages fails at render
... I solved it by using the same mechanism as nuxt.js default generated router does, wrapping the component dynamic import as follows:
Read more >React dynamic imports and route-centric code splitting guide
While developing on a local server, all our files are hosted from our computer's port. In React, the port is set to 3000...
Read more >[SOLVED] - Dynamic import not working - help - Meteor.js forums
This creates a new component everytime the route is rendered. Each re-render results to mount and unmount instead of just updating.
Read more >Advanced Features: Dynamic Import - Next.js
Dynamically import JavaScript modules and React Components and split your code into manageable chunks.
Read more >Manually Lazy Load Modules And Components In Angular
Since Angular 8 we can use the browser's built-in dynamic imports to load ... module can be defined in the routing configuration using...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi! Thanks for the extensive reporting and for working on this 🤗
I feel too that changing the public
render
interface to a Promise is a big deal. It would solve, however, several issues I encountered regarding the first “tick”, where stuff inmounted()
orcreated()
is not executed until we await one clock tick.It is a big deal, but I wonder if there’s any workaround on this. I’ll give a look soon and see what I can come up with!
Have a nice day 😄
I feel the suggestion above is valid enough so that we don’t need to overcomplicate router setup. As mentioned, VTL provides a comfortable way to set up the store and router, but you can always get the Vue instance and use it in your favor.
Thanks for posting this, though! 👍 It’ll be really helpful for anyone else running into issues with dynamic imports.
Closing it up!