Svelte page.js routing - Can't get passed-in props for dynamic component

353 views Asked by At

I have a problem with page.js routing. If I go from settings to a dashboard, i get the passed in props. If I go from dashboard to dashboard nothing is logged out... Can anyone help?

App.svelte

let page, props;

router("/settings", () => (page = Settings));

router("/dashboards/:dashboardId", (ctx) => {
    props = ctx.params;
    console.log("App", props);
    page = Dashboard;
});

<svelte:component this={page} {...props} />

Navigation.svelte

{#each $dashboards as dashboard}
    <div class="dashboard-link">
        <a href="/dashboards/{dashboard.id}">{dashboard.name}</a>
    </div>
{/each}

Dashboard.svelte

<script>
    export let dashboardId;
    console.log("dashboardId", dashboardId);
</script>
1

There are 1 answers

0
Ivan On

The code actually works. The problem was that the console.log works only during initialization i.e. from settings to dashboard, dashboard loads. From dashboard to dashboard, only the variables change i.e. component is already loaded.