2020-11-13 16:42:32 +01:00
|
|
|
<script>
|
2021-02-10 16:49:23 +01:00
|
|
|
import { getContext } from "svelte"
|
2020-11-13 16:42:32 +01:00
|
|
|
import Router from "svelte-spa-router"
|
2020-11-24 10:31:54 +01:00
|
|
|
import { routeStore } from "../store"
|
2020-11-13 16:42:32 +01:00
|
|
|
import Screen from "./Screen.svelte"
|
2021-05-20 15:47:17 +02:00
|
|
|
import { onMount } from "svelte"
|
2020-11-13 16:42:32 +01:00
|
|
|
|
2020-11-20 10:50:10 +01:00
|
|
|
const { styleable } = getContext("sdk")
|
2020-11-24 12:02:10 +01:00
|
|
|
const component = getContext("component")
|
2020-11-20 10:50:10 +01:00
|
|
|
|
2020-12-11 15:24:19 +01:00
|
|
|
// Only wrap this as an array to take advantage of svelte keying,
|
|
|
|
// to ensure the svelte-spa-router is fully remounted when route config
|
|
|
|
// changes
|
2021-02-10 16:49:23 +01:00
|
|
|
$: config = {
|
|
|
|
routes: getRouterConfig($routeStore.routes),
|
|
|
|
id: $routeStore.routeSessionId,
|
|
|
|
}
|
2020-11-13 16:42:32 +01:00
|
|
|
|
2020-11-19 19:39:22 +01:00
|
|
|
const getRouterConfig = routes => {
|
|
|
|
let config = {}
|
|
|
|
routes.forEach(route => {
|
|
|
|
config[route.path] = Screen
|
2020-11-13 16:42:32 +01:00
|
|
|
})
|
2020-11-17 13:08:24 +01:00
|
|
|
|
|
|
|
// Add catch-all route so that we serve the Screen component always
|
2020-11-19 19:39:22 +01:00
|
|
|
config["*"] = Screen
|
|
|
|
return config
|
|
|
|
}
|
2020-11-13 16:42:32 +01:00
|
|
|
|
2020-11-19 19:39:22 +01:00
|
|
|
const onRouteLoading = ({ detail }) => {
|
2020-11-17 13:08:24 +01:00
|
|
|
routeStore.actions.setActiveRoute(detail.route)
|
2020-11-13 16:42:32 +01:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2021-02-10 16:49:23 +01:00
|
|
|
{#key config.id}
|
2020-11-24 12:02:10 +01:00
|
|
|
<div use:styleable={$component.styles}>
|
2020-12-11 15:24:19 +01:00
|
|
|
<Router on:routeLoading={onRouteLoading} routes={config.routes} />
|
2020-11-17 13:08:24 +01:00
|
|
|
</div>
|
2021-02-10 16:49:23 +01:00
|
|
|
{/key}
|
2020-11-25 19:30:09 +01:00
|
|
|
|
|
|
|
<style>
|
|
|
|
div {
|
|
|
|
position: relative;
|
2021-06-08 16:16:37 +02:00
|
|
|
overflow-x: auto;
|
2020-11-25 19:30:09 +01:00
|
|
|
}
|
|
|
|
</style>
|