refactor(router-view): render children as placeholder #2799
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is not a bug, but the way I use
router-view
is that it has a placeholder using therouter-view
children before rendering it with the actual view from the component. Here's a little demo:https://codesandbox.io/s/vue-routing-example-b1t5d
You see that there's a slight delay before the route component gets rendered. It gets quite apparent when you have a
beforeEach
navigation guard that delays the route to be rendered. The 'blinking' effect between the blank page and the rendered component is undesirable and I am trying to improve it.I tried using async component to no avail, and it turned out that the cause was when the router is initialized, it is validating an initial route, and it is rendering an empty node since there is no match. This explains the blank page/element that I was facing.
My proposal is to render the children instead of an empty node, so that there is something to be rendered before the route component takes place. This applies to any kinds of route mismatches though. I made a little example and an e2e test to demonstrate the change.
Also, I did search through the issues but none of it seemed to mention this problem (could be very specific to the problem I'm facing, or maybe I missed it, CMIIW), so if this isn't exactly what Vue Router is aiming for, I understand, but maybe you could suggest a solution for me 😅. But if this is good enough, that would be so great, though I'm not sure if I'm doing the e2e test right.
Anyhow, let me know! Thanks for Vue Router btw, I've been using it for the past 2 years and it's been terrific.