-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
"<router-view> can no longer be used directly inside <transition>" warning showing when router-view is not used directly inside transition. #1306
Comments
The warning shouldn't appear in this scenario indeed. Contribution welcome! BTW: It's worth noting, it's only a warning and it doesn't affect runtime, so you are totally fine |
Thanks for confirming that it's not an intended warning in this case. After digging into the warnDeprecatedUsage function where the warning is thrown, I believe the issue is that it only looks at the parent, which is the parent component, but not necessarily the parent dom element, so the parent subtree could contain other elements. What if the condition, after checking that the parent type is "KeepAlive" or contains "Transition", also checks that the parent subtree type is "RouterView"? That way it would ensure that the direct child of the "transition" or "keep-alive" is in fact the "router-view". function warnDeprecatedUsage() {
const instance = getCurrentInstance();
const parentName = instance.parent && instance.parent.type.name;
const parentDirectChild = instance.parent && instance.parent.subtree.type.name;
if (parentName && parentDirectChild &&
(parentName === 'KeepAlive' || parentName.includes('Transition')) &&
parentDirectChild === 'RouterView') {
const comp = parentName === 'KeepAlive' ? 'keep-alive' : 'transition';
warn(`<router-view> can no longer be used directly inside <transition> or <keep-alive>.\n` +
`Use slot props instead:\n\n` +
`<router-view v-slot="{ Component }">\n` +
` <${comp}>\n` +
` <component :is="Component" />\n` +
` </${comp}>\n` +
`</router-view>`);
}
} |
I don't think that would be enough but feel free to give this a try. There are a few existing test cases in |
It works in my own testing, but what do you believe it may be missing? |
cases that combine KeepAlive, Suspense, etc. I tested locally and it didn't pass the tests. |
Ah, ok, thanks for trying it out. Is there anyway to disable/suppress this specific warning like we can with configureCompat? |
This comment was marked as spam.
This comment was marked as spam.
Can we get this fixed, please? |
Here's a little workaround for the time being, using a functional component wrapper around router-view. |
> <router-view> can no longer be used directly inside <transition> See - vuejs/router#1306 - vuejs/router#1797
Version
4.0.12
Reproduction link
jsfiddle.net/8gxaptq2/
Steps to reproduce
Run and view warning in the console.
What is expected?
No warning.
What is actually happening?
The warning is displayed in the console.
I believe this is a bug because the warning specifically states that router-view can no longer be used directly inside, yet it is shown when not used directly inside, and also the router-view does work inside of a transition that is not its direct parent.
The text was updated successfully, but these errors were encountered: