-
Notifications
You must be signed in to change notification settings - Fork 247
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
Persistent layout problems #613
Comments
Feel free to share more code samples or a repo with an example of this and I can suggest some specific solutions! |
Thanks for the reply. After more research it seems that 'Peristent' layouts in Inertia behave differently than I expected. Properties of persistent layouts are non-reactive. That's why my template wasn't updating on route change. If you still need persistent layouts then I will add my solution below. For the moment I can do without them, but I know they are useful for some things. ORIGINAL CODE (my 'active' link never updated with persistent layouts):
SOLUTION FOR PERSISTENT LAYOUTS:
|
While the solution of @stuartcusackie works, I used a slightly different approach which forces the nav component to refresh on each navigation, meaning you can still use the <template>
<nav :key="currentRoute" class="flex">
<NavBarLink
:href="route('home')"
:active="route.current('home')"
>Home</NavBarLink>
<NavBarLink
:href="route('artists.index')"
:active="route.current('artists.*')"
>Artists</NavBarLink>
</nav>
</template>
<script setup>
import { ref } from 'vue';
import { router } from '@inertiajs/vue3';
import NavBarLink from '@/Components/NavBarLink.vue';
const currentRoute = ref(null);
router.on('navigate', () => {
currentRoute.value = route().current();
})
</script> It listens to Inertia's navigate event and updates the local More info about this 'key changing technique': https://michaelnthiessen.com/key-changing-technique/ |
I just ran into this myself. I'm not using a persistent layout; just a child layout component. Since the Ziggy method won't work on its own, wouldn't it be simpler to bypass it and add the current route via the E.g., return array_merge(parent::share($request), [
currentRoute' => fn () => Route::currentRouteName(),
]); Then in the layout component: <script setup>
import { Link, usePage } from '@inertiajs/vue3';
const {props} = usePage()
</script>
<template>
<div>{{ props.currentRoute }} </div>
</template> |
Shouldn't this be reactive in a way ? |
Ziggy version
1.5.0
Laravel version
9.48.0
Description
Following on from this issue, route().current() does not update when using inertia persistent / default layouts. The return value never changes after initial app load.
I'm not sure if this is an Inertia or Ziggy problem. I can open an inertia issue but I'm not sure how to address it.
I have tested this like so:
route().current() does not update
route().current() does not update
route().current() updates
Ziggy call and context
Ziggy configuration
Route definition
The text was updated successfully, but these errors were encountered: