Here's the code inside my Vue component:
import { usePage } from '@inertiajs/vue3';
import { usePage as usePage2 } from '@inertiajs/inertia-vue3';
const page = usePage();
console.log('page', page, page.props, page.value);
const page2 = ref(usePage2());
console.log ('page2', page2, page2.value.props.auth.authenticated);
In the browser's console I get:
page Proxy undefined undefined // not what I want; can't access my props!
page2 Object false // correct answer
However, the library @inertiajs/vue3 is supposed to replace the deprecated @inertiajs/inertia-vue3, isn't it?
- So why am I able to access the page props in
page2but not inpage? - Moreover, why do I have to wrap the second option in a
ref()? If I remove theref()aroundusePage2()it fails with anundefinedvalue again; and when wrapping the first solution with areflike thisref(usePage()), it doesn't fix the problem either!
The documentation is a bit lacking on exactly how usePage() works in the composition API. And even my AI can't figure out what's going on. I'd like to use the non-deprecated version if possible!!
P.S. It shouldn't make any difference, but my authenticaed prop should return false (until the user logs in). The props are passed in via the HandleInertiaRequests{} PHP class.
public function share(Request $request): array
return array_merge (parent::share($request), [
'auth' => [
'authenticated' => Auth::check(), // plus some other props
],
]);
}
