mirror of
https://github.com/Fluffy-Bean/TastyBites.git
synced 2025-05-29 23:03:13 +00:00
Add a router and some temporary pages
This commit is contained in:
parent
56bd273711
commit
677ef885cf
9 changed files with 96 additions and 4 deletions
|
@ -1,9 +1,45 @@
|
|||
<script>
|
||||
import Router from 'svelte-spa-router';
|
||||
import { replace, link, location } from 'svelte-spa-router';
|
||||
import active from 'svelte-spa-router/active'
|
||||
import routes from './routes';
|
||||
|
||||
let oldLocation = undefined;
|
||||
let showNavBar = false;
|
||||
|
||||
function routeLoading(event) {
|
||||
if (event.detail.location === oldLocation) {
|
||||
return; // not an actual change
|
||||
}
|
||||
showNavBar = event.detail.userData.showNavBar;
|
||||
oldLocation = event.detail.location;
|
||||
}
|
||||
|
||||
function conditionFailure(event) {
|
||||
replace("/");
|
||||
}
|
||||
</script>
|
||||
|
||||
<main>
|
||||
<h1>TastyBites</h1>
|
||||
</main>
|
||||
{#if showNavBar }
|
||||
<nav>
|
||||
<p>TastyBites</p>
|
||||
<ul>
|
||||
<li><a href="/" use:link use:active>Home</a></li>
|
||||
<li><a href="/contact" use:link use:active>Contact Us</a></li>
|
||||
<li><a href="/cart" use:link use:active>Shopping Cart</a></li>
|
||||
</ul>
|
||||
<p>Location: {$location}</p>
|
||||
</nav>
|
||||
{/if}
|
||||
<Router
|
||||
{routes}
|
||||
restoreScrollState={true}
|
||||
on:routeLoading={routeLoading}
|
||||
on:conditionsFailed={conditionFailure}
|
||||
/>
|
||||
<footer>
|
||||
<p>TastyBites is a fake restaurant</p>
|
||||
</footer>
|
||||
|
||||
<style>
|
||||
</style>
|
||||
|
|
25
front/src/routes.js
Normal file
25
front/src/routes.js
Normal file
|
@ -0,0 +1,25 @@
|
|||
import { wrap } from "svelte-spa-router/wrap";
|
||||
import PageLoading from "./routes/PageLoading.svelte";
|
||||
|
||||
const routes = {
|
||||
"/": wrap({
|
||||
asyncComponent: () => import("./routes/PageIndex.svelte"),
|
||||
loadingComponent: PageLoading,
|
||||
conditions: [],
|
||||
userData: { showNavBar: true },
|
||||
}),
|
||||
"/contact": wrap({
|
||||
asyncComponent: () => import("./routes/PageContact.svelte"),
|
||||
loadingComponent: PageLoading,
|
||||
conditions: [],
|
||||
userData: { showNavBar: true },
|
||||
}),
|
||||
"/cart": wrap({
|
||||
asyncComponent: () => import("./routes/PageShoppingCart.svelte"),
|
||||
loadingComponent: PageLoading,
|
||||
conditions: [],
|
||||
userData: { showNavBar: true },
|
||||
}),
|
||||
}
|
||||
|
||||
export default routes;
|
2
front/src/routes/PageContact.svelte
Normal file
2
front/src/routes/PageContact.svelte
Normal file
|
@ -0,0 +1,2 @@
|
|||
<h1>Contact us</h1>
|
||||
<p>Nuh uh</p>
|
2
front/src/routes/PageIndex.svelte
Normal file
2
front/src/routes/PageIndex.svelte
Normal file
|
@ -0,0 +1,2 @@
|
|||
<h1>TastyBites reeeee</h1>
|
||||
<p>aurgh</p>
|
1
front/src/routes/PageLoading.svelte
Normal file
1
front/src/routes/PageLoading.svelte
Normal file
|
@ -0,0 +1 @@
|
|||
<p>Loading</p>
|
2
front/src/routes/PageShoppingCart.svelte
Normal file
2
front/src/routes/PageShoppingCart.svelte
Normal file
|
@ -0,0 +1,2 @@
|
|||
<h1>Shopping Cart</h1>
|
||||
<p>Empty....</p>
|
Loading…
Add table
Add a link
Reference in a new issue