3

I building an application with vue 3.0 and vue-router 4.0.

I have this very simple code in my App.vue component (first rendered component) :

<router-view v-slot="{ Component }">
    <transition name="fade" mode="out-in" appear>
        <component :is="Component"></component>
    </transition>
</router-view>

First page is renderer - no problem. But as soon as I navigate to another page, page become blank. If I remove the mode="out-in" it works (but transition is ugly).

Does anyone know why ?

37 Degres
  • 141
  • 7

3 Answers3

11

I finally found were the mistake was, and how stupid it was...

In my template, I put a comment before the first tag:

<template>

    <!-- login layout --> <=== NOT A GOOD IDEA...
    <div class="lsn-login">
        ...
    </div>

</template>

Thank you for all your comment.

37 Degres
  • 141
  • 7
  • 2
    Thanks, it helped! Mark it as answer! This is really weird, comments must not affect rendering. – Georgiy Bukharov Feb 25 '22 at 12:40
  • Faced this problem today. Spent solid 2 hours reading through official documents and migrations [here](https://router.vuejs.org/guide/migration/#router-view-keep-alive-and-transition) and [there](https://github.com/vuejs/rfcs/blob/master/active-rfcs/0034-router-view-keep-alive-transitions.md#summary). Just to finally comes out that my comment is the problem. This is wierd – Huy Phạm May 25 '22 at 03:16
  • Thanks a lot, I would have search for hours, couldn't imagine this problem – Alex Baur Nov 01 '22 at 14:44
  • To be clear, the answer is a combination of this and Fabio Almeida's below: the real answer is that you can only have 1 root node when using transitions (with the comment counting as a node) – Charles Chen Jun 21 '23 at 17:12
3

Each template can only have one tag (element). The following example would break the transitions

<template>
  <div class="about"></div>
  <img class="back-img" src="/artwork/58.webp"/>
</template>
2

The reason for this problem is that transition only supports a single element. The official document hints:

<Transition> only supports a single element or component as its slot content. 
If the content is a component, the component must also have only one single root element.

You can see a demo in this link: https://stackblitz.com/edit/vitejs-vite-gwfbmb?file=src%2FApp.vue

FreezeNow
  • 21
  • 2