A Minimal Svelte Router

Here is a minimal router for Svelte v3 using Page.js.

Whenever the route changes, Page.js sets a variable that holds the component that should be rendered for the route.

  import page from 'page';

  import Home from './views/Home.svelte';

  let route;
  let routeParams;

  function setRoute(r) {
    return function({ params }) {
      route = r;
      routeParams = params;

  page("/", setRoute(Home));
  page({ hashbang: true });

<svelte:component this={route} bind:params={routeParams} />