first working router 🎉

This commit is contained in:
2020-12-19 18:27:48 +01:00
parent d2b2542412
commit b4d13701a7
4 changed files with 39 additions and 10 deletions

View File

@@ -1,4 +1,7 @@
<script>
import Router from "svelte-spa-router";
import { replace } from "svelte-spa-router";
import { wrap } from "svelte-spa-router/wrap";
import { addMessages, init, getLocaleFromNavigator } from "svelte-i18n";
import en from "./locales/en";
import de from "./locales/de";
@@ -12,17 +15,39 @@
import Login from "./components/Login.svelte";
import Dashboard from "./components/Dashboard.svelte";
import Footer from "./components/Footer.svelte";
import NotFound from "./components/NotFound.svelte";
import Tracks from "./components/Tracks.svelte";
// import Profile from "./components/Profile.svelte";
import store from "./store.js";
import ForgotPassword from "./components/ForgotPassword.svelte";
store.init();
$: logged_in = $store.isLoggedIn;
//
const checkAuth = (detail) => {
if (!$store.isLoggedIn) {
console.log("not authed");
replace("/login/");
return false;
}
return true;
};
const routes = {
"/login": Login,
"/forgot_password": ForgotPassword,
"/dashboard": wrap({ component: Dashboard, conditions: [checkAuth] }),
"/": wrap({ component: Dashboard, conditions: [checkAuth] }),
// Using named parameters, with last being optional
// "/author/:first/:last?": Author,
// Wildcard parameter
// "/book/*": Book,
// Catch-all
// This is optional, but if present it must be the last
"*": NotFound,
};
//
</script>
{#if logged_in === true}
<Dashboard />
<Footer />
<!-- <Profile /> -->
{:else}
<Login />
{/if}
<Router {routes} />