-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Vue router crashes when top level route target is wrapped in transition but has no child routes yet #2121
Comments
It looks like a dup of one of the transition issues in Vue core. Maybe vuejs/core#3950. Feel free to investigate further. |
I've found that it is even caused by commented out
then navigation between all routes is working fine. But when you use that code, even though it does exactly the same as above, router navigation is broken as well:
|
I don't see how this is related. I'm not using keep-alive here in my example. With my previous comment one can suspect, that there's a deeper issue than vue-router, though. |
vant4源代码中移动端路由如果是树形的貌似不被支持 |
According to deepl your comment translates to:
I don't understand the relation to my post. What do you mean by "Mobile routing"? I have a client-side SPA. The problem described happens in the local desktop browser, not on a mobile device. |
Also, given my comment with the examples above, consider the last example vs this one:
When you remove the commented out My guess is, that the commented out code is not treated as commented out. That might be a totally separate issue with the vue template compiler, but I'm not sure about that. Any thoughts on that @posva? |
According to the official documentation 2. doesn't resemble the examples. ✅ Confirmed that 1. solves the issue and is closest to the official documentation. import { RouterView, useRoute } from 'vue-router'
const route = useRoute()
...
<RouterView v-slot="{ Component }" class="content" :key="route.fullPath">
<Transition :name="(route?.meta?.transition as string) || 'fade'" mode="out-in" appear>
<component :is="Component" />
</Transition>
</RouterView> With 1. solving the issue, the official documentation is wrong and that issue here should be used to update that documentation please. |
The documentation update avoids situations described in vuejs#2121 and provides a link to a working demonstration project at Stackblitz.
PR for updated documentation: #2126 |
I believe it's this: vuejs/core#6080. The With route C you end up in effectively the same scenario, because |
Indeed, wrapping the |
Reproduction
For reproduction please see the provided Stackblitz project
Steps to reproduce the bug
Here's a stackblitz project reproducing the issue: Vue + Vue Router Error Reproduction
Howto see the reproduction
First four steps show that transitions are working for Route A and Route B, even when going to Route C.
Expected behavior
Vue router should silently ignore when there are no children defined in the router config yet (iterative approach of software development). Even if it doesn't ignore them, navigation away to a previously working route should be possible without having to reload the application in the browser tab.
Actual behavior
The top level router view in
App.vue
is wrapped in aTransition
and for all top level router targets view components are there.Three top level targets defined in their template a child
<ViewRouter></ViewRouter>
but the third, "Crashes C" has no children defined yet. When navigating to that top level target "Crashes C" and then to some other route, view router crashes.Side-effect: When staying in Route "Crashes C" reloading the browser tab to restart the app will let a user stick in that route since navigating away from it will crash the vue router again.
Additional information
Edit on 2024-02-01:
I've updated the StackBlitz to contain the Routes "Works D", "Crashes E" and "Works F" with the examples codes from my comments below.
Specifically "Crashes E" and "Works F" are a real mystery since the only difference is the missing commented out RouterView in the template section in "Works F".
Edit on 2024-02-02:
With @K332's answer below I gave the final section in the official documentation a try, which adds
:key="route.path"
to the innercomponent
tag. Doing that, I now get to see the error in the browser console when navigating away from a "Crashes" route:No response
The text was updated successfully, but these errors were encountered: