Skip to content
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

Svelte Context is Lost #49

Open
abegehr opened this issue Feb 5, 2025 · 0 comments
Open

Svelte Context is Lost #49

abegehr opened this issue Feb 5, 2025 · 0 comments

Comments

@abegehr
Copy link

abegehr commented Feb 5, 2025

Svelte context doesn't seem to be preserved from outside the router to inside:

App.svelte:

<script lang="ts">
  import type { Route } from "@mateothegreat/svelte5-router";
  import { Router } from "@mateothegreat/svelte5-router";
  import Home from "./Home.svelte";
  import { setContext } from "svelte";
  import { Store } from "./store.svelte";

  setContext("STORE", new Store());

  const routes: Route[] = [
    {
      path: "/",
      component: Home,
    }
  ];
</script>

<Router {routes} />

Home.svelte

<script lang="ts">
  import { setContext } from "svelte";
  import { Store } from "./store.svelte";

  const store = getContext<Store>("STORE"); // is undefined
</script>

<div>
  <!-- … -->
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant