0.0.5 • Published 10 months ago

@teleology/svelte-router v0.0.5

Weekly downloads
-
License
MIT
Repository
-
Last release
10 months ago

@teleology/svelte-router

Tested against Svelte 5.1.3. This is a library for SPA's and does not support SSR at this time.

API

Router Usage

<script lang="ts">
  import { Router } from "@teleology/svelte-router"

  import { Test } from "./routes/Test.svelte"

  let isAuthenticated = true;

  const routes = [
    {
      path: "*",
      // lazy loaded
      component: () => import("./lib/routes/NotFound.svelte"),
    },
    {
      path: "/test"
      // non-lazy load
      component: Test,
    },
    {
      path: "/user",
      component: () => import("./lib/routes/UserProfile.svelte"),
      layout: () => import("./lib/pages/UserLayout.svelte"),
      redirect: "/",
      guard: () => isAuthenticated
    }
  ]
</script>

<Router {routes}>

RouteDefinition

Route Usage

<script lang="ts">
  import { push, type RouteDetails } from "@teleology/svelte-router";

  interface Props {
    route: RouteDetails;
  }

  let { route }: Props = $props();
</script>

<h1>You landed on {route.pathname}</h1>

RouteDetails

Route details are extends from the browser Location object

Utils

  • push(url: string, state?: any)
  • replace(url: string, state?: any)
  • back()
0.0.5

10 months ago

0.0.4

10 months ago

0.0.3

10 months ago

0.0.2

10 months ago

0.0.1

10 months ago