Certainly! Let’s break down what’s happening and how to resolve it.
1. Why does usePage() from @inertiajs/vue3 not work as expected in Vue 3 Composition API?
The Problem
When you use:
import { usePage } from '@inertiajs/vue3';
const page = usePage();
console.log(page, page.props); // page.props is undefined
You’re seeing page.props as undefined. That’s because, in Vue 3 with Inertia’s new package (@inertiajs/vue3), usePage() returns a Vue ref (a reactive reference), not a plain object.
So, to access the actual page object, you need to use .value:
const page = usePage();
console.log(page.value.props); // This should work
Correct Usage
If you want to access props reactively, you should do:
const page = usePage();
const authenticated = computed(() => page.value.props.auth.authenticated);
2. Why does usePage2() from @inertiajs/inertia-vue3 work differently?
The old package (@inertiajs/inertia-vue3) returned the page object directly, not a ref. That’s why you could access page2.props directly. If you wrap it in a ref(), you get a double ref, which is not necessary.
3. Why does wrapping usePage() in ref() not help?
Because usePage() already returns a ref. Wrapping it in another ref() just gives you a ref to a ref, which is not what you want.
Summary Table
| Package | What usePage() returns |
How to access props |
|---|---|---|
@inertiajs/inertia-vue3 |
Plain object | page.props |
@inertiajs/vue3 |
Vue ref | page.value.props |
How to Fix Your Code
Update your code to use .value with the new package:
<script setup>
import { computed } from 'vue';
import { usePage } from '@inertiajs/vue3';
const page = usePage();
const authenticated = computed(() => page.value.props.auth.authenticated);
console.log('page', page, page.value, page.value.props);
</script>
No need to wrap usePage() in ref()!
Extra: Why does the docs not mention this?
The Inertia docs for Vue 3 do mention that usePage() returns a ref. But it’s easy to miss if you’re used to the old API. Always remember: in Vue 3, most composables return refs for reactivity.
TL;DR
- With
@inertiajs/vue3, always use.valueto access the actual page object returned byusePage(). - Don’t wrap
usePage()inref(). - Update your computed properties to use
page.value.props.
Example:
const page = usePage();
const authenticated = computed(() => page.value.props.auth.authenticated);
That should resolve your issue!