1
0
Fork 0
mirror of synced 2024-09-28 07:11:40 +12:00
budibase/packages/client/src/components/Router.svelte

32 lines
789 B
Svelte
Raw Normal View History

<script>
import { onMount } from "svelte"
import Router from "svelte-spa-router"
import { routeStore, screenStore } from "../store"
import Screen from "./Screen.svelte"
import { styleable } from "../utils"
export let styles
$: routerConfig = getRouterConfig($routeStore.routes)
const getRouterConfig = routes => {
let config = {}
routes.forEach(route => {
config[route.path] = Screen
})
// Add catch-all route so that we serve the Screen component always
config["*"] = Screen
return config
}
const onRouteLoading = ({ detail }) => {
routeStore.actions.setActiveRoute(detail.route)
}
</script>
{#if routerConfig}
<div use:styleable={styles}>
<Router on:routeLoading={onRouteLoading} routes={routerConfig} />
</div>
{/if}