2024-04-04 16:01:08 +02:00
|
|
|
<script>
|
|
|
|
import { onMount, onDestroy } from 'svelte';
|
2022-12-20 00:34:45 +01:00
|
|
|
import LoginPage from './pages/LoginPage.svelte';
|
|
|
|
import DashboardPage from './pages/DashboardPage.svelte';
|
2024-04-04 16:01:08 +02:00
|
|
|
|
|
|
|
let path = '';
|
|
|
|
function updatePath() {
|
|
|
|
path = window.location.pathname;
|
|
|
|
}
|
|
|
|
onMount(() => {
|
|
|
|
updatePath();
|
|
|
|
window.addEventListener('popstate', updatePath);
|
|
|
|
});
|
|
|
|
onDestroy(() => {
|
|
|
|
window.removeEventListener('popstate', updatePath);
|
|
|
|
});
|
|
|
|
/**
|
|
|
|
* @param newPath {string}
|
|
|
|
*/
|
|
|
|
function navigate(newPath) {
|
|
|
|
history.pushState({}, '', newPath);
|
|
|
|
updatePath();
|
|
|
|
}
|
2022-03-11 15:46:11 -08:00
|
|
|
</script>
|
|
|
|
|
2024-04-04 16:01:08 +02:00
|
|
|
<header>
|
|
|
|
<a on:click={(e) => { e.preventDefault(); navigate('/'); }} href='/login'>Login</a>
|
|
|
|
<a on:click={(e) => { e.preventDefault(); navigate('/dashboard'); }} href='/dashboard'>Dashboard</a>
|
|
|
|
</header>
|
|
|
|
{#if path === '/'}
|
|
|
|
<LoginPage />
|
|
|
|
{:else if path === '/dashboard'}
|
|
|
|
<DashboardPage />
|
|
|
|
{/if}
|