Skip to content

Commit 4b02a34

Browse files
committed
demo: Remove the use of Route.when
This has restored functionality to the Fallback content in the demo.
1 parent fbcadd0 commit 4b02a34

File tree

2 files changed

+65
-52
lines changed

2 files changed

+65
-52
lines changed

demo/src/App.svelte

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
const timer = setTimeout(() => {
1616
showNavTooltip = true;
1717
}, 2000);
18-
18+
1919
// Hide tooltip after 10 seconds or when user interacts
2020
const hideTimer = setTimeout(() => {
2121
showNavTooltip = false;
2222
}, 12000);
23-
23+
2424
return () => {
2525
clearTimeout(timer);
2626
clearTimeout(hideTimer);
@@ -31,33 +31,35 @@
3131
<div class="app">
3232
<div class="d-flex flex-column h-100">
3333
<Router id="root">
34-
<Tooltip shown={showNavTooltip} placement="bottom">
35-
{#snippet reference(ref)}
36-
<NavBar {@attach ref} />
37-
{/snippet}
38-
Use these navigation links to test-drive the routing capabilities of @wjfe/n-savant.
39-
</Tooltip>
40-
<main class="d-flex flex-column flex-fill overflow-auto mt-3">
41-
<div class="container-fluid flex-fill d-flex flex-column">
42-
<div class="grid flex-fill">
43-
<Route key="home" path="/">
44-
<HomeView />
45-
</Route>
46-
<Route key="pathRouting" path="/path-routing/*">
47-
<PathRoutingView basePath="/path-routing" />
48-
</Route>
49-
<Route key="hashRouting" path="/hash-routing">
50-
<HashRoutingView basePath="/hash-routing" />
51-
</Route>
52-
<Fallback>
53-
<NotFound />
54-
</Fallback>
34+
{#snippet children(_, rs)}
35+
<Tooltip shown={showNavTooltip} placement="bottom">
36+
{#snippet reference(ref)}
37+
<NavBar {@attach ref} />
38+
{/snippet}
39+
Use these navigation links to test-drive the routing capabilities of @wjfe/n-savant.
40+
</Tooltip>
41+
<main class="d-flex flex-column flex-fill overflow-auto mt-3">
42+
<div class="container-fluid flex-fill d-flex flex-column">
43+
<div class="grid flex-fill">
44+
<Route key="home" path="/">
45+
<HomeView />
46+
</Route>
47+
<Route key="pathRouting" path="/path-routing/*">
48+
<PathRoutingView basePath="/path-routing" />
49+
</Route>
50+
<Route key="hashRouting" path="/hash-routing">
51+
<HashRoutingView basePath="/hash-routing" />
52+
</Route>
53+
<Fallback>
54+
<NotFound />
55+
</Fallback>
56+
</div>
5557
</div>
56-
</div>
57-
</main>
58-
<Route key="notHome" when={(rs) => !rs.home.match}>
59-
<RouterTrace />
60-
</Route>
58+
</main>
59+
{#if !rs.home.match}
60+
<RouterTrace />
61+
{/if}
62+
{/snippet}
6163
</Router>
6264
</div>
6365
</div>

demo/src/lib/NavBar.svelte

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
import { routingMode } from './hash-routing';
55
import type { HTMLAttributes } from 'svelte/elements';
66
7-
let {
8-
...restProps
9-
}: HTMLAttributes<HTMLElement> = $props();
7+
let { ...restProps }: HTMLAttributes<HTMLElement> = $props();
108
119
const pathRoutingLinks = [
1210
{ text: 'Home', href: '/path-routing' },
@@ -62,32 +60,45 @@
6260
<div class="collapse navbar-collapse" id="navbarNav">
6361
<ul class="navbar-nav">
6462
<li class="nav-item">
65-
<Link class="nav-link" activeState={{ class: 'active', key: 'home' }} href="/" id="homeLink">Home</Link>
63+
<Link
64+
class="nav-link"
65+
activeState={{ class: 'active', key: 'home' }}
66+
href="/"
67+
id="homeLink">Home</Link
68+
>
6669
</li>
67-
<Route key="homeMenuPr" when={(rs) => !rs.pathRouting?.match}>
68-
<li class="nav-item">
69-
<Link
70-
class="nav-link"
71-
activeState={{ class: 'active', key: 'pathRouting' }}
72-
href="/path-routing"
73-
>
74-
Path Routing
75-
</Link>
76-
</li>
70+
<Route key="homeMenuPr">
71+
{#snippet children(rp, _, rs)}
72+
{#if !rs.pathRouting?.match}
73+
<li class="nav-item">
74+
<Link
75+
class="nav-link"
76+
activeState={{ class: 'active', key: 'pathRouting' }}
77+
href="/path-routing"
78+
>
79+
Path Routing
80+
</Link>
81+
</li>
82+
{/if}
83+
{/snippet}
7784
</Route>
7885
<Route key="pathRouting">
7986
<SubNav title="Path Routing" links={pathRoutingLinks} />
8087
</Route>
81-
<Route key="homeMenuHr" when={(rs) => !rs.hashRouting?.match}>
82-
<li class="nav-item">
83-
<Link
84-
class="nav-link"
85-
activeState={{ class: 'active', key: 'hashRouting' }}
86-
href="/hash-routing"
87-
>
88-
Hash Routing
89-
</Link>
90-
</li>
88+
<Route key="homeMenuHr">
89+
{#snippet children(rp, _, rs)}
90+
{#if !rs.hashRouting?.match}
91+
<li class="nav-item">
92+
<Link
93+
class="nav-link"
94+
activeState={{ class: 'active', key: 'hashRouting' }}
95+
href="/hash-routing"
96+
>
97+
Hash Routing
98+
</Link>
99+
</li>
100+
{/if}
101+
{/snippet}
91102
</Route>
92103
<Route key="hashRouting">
93104
<SubNav title="Hash Routing" links={hashRoutingLinks} />

0 commit comments

Comments
 (0)