I'm new to Svelte and SvelteKit, and I have the following problem:
I have a navbar component inside the lib folder which I made like this:
<script>
import { store } from "../store";
let title;
store.subscribe((data) => {
title = data.title;
});
</script>
<ul class="nav align-items-center bg-light border-bottom border-black">
<li class="nav-item flex-grow-1">
<span
class="nav-link fs-2 py-1 pe-0 ps-4 text-black fw-medium text-center"
>{title}</span
>
</li>
<li class="nav-item">
<select
class="form-select form-select-sm bg-light border-0 text-black text-decoration-underline"
>
<option value="EN">EN</option>
</select>
</li>
</ul>
Then I have this store:
import { writable } from "svelte/store";
export const store = writable({
title: "Integma Check",
plant: null,
language: null,
functions: null,
checks: null,
});
I'm also using +layout.svelte:
<script>
import Navbar from "../lib/Navbar.svelte";
</script>
<Navbar />
<slot />
Then I have some routes (+page.svelte).
My question is: how can I change the title variable of navbar component, on route change? Basically I want, if i go to route ABC, navbar title should be ABC, if I go back to home route, navbar title should be Integma Check (store default value). I tried playing with stores, to update the title, but on back button of the browser, the title stays as the last updated value...which I think is normal, because from what I understand, stores are like a global value or something. I also have a feeling the problem is somehow related with +layout.svelte. I also tried playing with onMount and onDestroy, but I get same results.
$storesyntax instead.