Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Kaluna's avatar
Level 2

Laravel + Inertia + Vue3 — Page transition woes

Hey everyone,

I cannot fathom for the life of me why this isn't working.

So, I have a page that "wraps" around everything so I can animate in/out the pages.

<script setup>
import { usePage } from '@inertiajs/vue3';
import { reactive, onMounted, onUnmounted } from 'vue'
const props = reactive(['is_loaded']);

onMounted(() => {
    props.is_loaded = true;

});

onUnmounted(() => {
    props.is_loaded = false;
});

</script>

<template>
    <transition>
        <div v-if="true === props.is_loaded">
            <slot />
        </div>
    </transition>
</template>

I've added all sorts of css—but nothing actually animates the page when I click on a <Link/> element.

I notice that when I change page, the containing "div" class does change, but doesn't seem to add any transition classes whatsoever.

It's hella frustrating. Any tips welcomed.

0 likes
1 reply
LaryAI's avatar
Level 58

It looks like you're trying to implement page transitions using Vue's <transition> component in a Laravel + Inertia + Vue3 setup. The issue might be related to how the transition classes are being applied and how the v-if directive is being used.

Here’s a refined approach to ensure that the transition classes are correctly applied and the transitions work as expected:

  1. Ensure Transition Classes: Make sure you have the necessary CSS classes for the transition. Vue's <transition> component uses specific classes to handle the transition states.

  2. Use v-show Instead of v-if: Sometimes using v-if can cause issues because it completely removes the element from the DOM. Using v-show might be more appropriate as it only toggles the visibility.

  3. Check Transition Name: Ensure you are using a transition name that matches your CSS classes.

Here’s an updated version of your code:

Explanation:

  1. Reactive State: The props object is now correctly initialized with is_loaded: false.

  2. Transition Name: The <transition> component is given a name attribute (name="fade"), which will be used to apply the transition classes.

  3. CSS Classes: The CSS classes for the transition are defined within a <style scoped> block. These classes handle the transition effects:

    • .fade-enter-active and .fade-leave-active define the duration of the transition.
    • .fade-enter and .fade-leave-to set the initial and final states of the transition.
  4. v-show Directive: The v-show directive is used instead of v-if to toggle the visibility of the element without removing it from the DOM.

This should help you achieve the desired page transition effect. If you still encounter issues, ensure that your CSS is correctly loaded and that there are no conflicting styles affecting the transition.

Please or to participate in this conversation.