]> git.r.bdr.sh - rbdr/forum/blame - app/forum.svelte
Add a router
[rbdr/forum] / app / forum.svelte
CommitLineData
890274a7 1<script>
24be7b53
BB
2 import LightRouter from 'lightrouter';
3
890274a7
BB
4 import ForumList from './components/forum_list/forum_list.svelte';
5 import Header from './components/header/header.svelte';
24be7b53
BB
6
7 // Routed Components
8 import Author from './components/author/author.svelte';
9 import Home from './components/home/home.svelte';
10 import InvalidRoute from './components/invalid_route/invalid_route.svelte';
11 import Post from './components/post/post.svelte';
66dc4cae 12 import Topic from './components/topic/topic.svelte';
24be7b53
BB
13 import TopicIndex from './components/topic_index/topic_index.svelte';
14
15 let page;
16 let params;
17
18 // sets the route params and current page.
19
20 const setRoute = function setRoute(targetPage) {
21
22 return function (routerParams) {
23 params = routerParams;
24 page = targetPage;
25 }
26 }
27
28 const router = new LightRouter({
29 routes: {
30 '': () => page = Home,
31 'f/{id}': setRoute(TopicIndex),
32 'g/{id}': setRoute(TopicIndex),
33 'a/{id}': setRoute(Author),
34 't/{id}': setRoute(Topic),
35 'p/{id}': setRoute(Post),
36 '.*': setRoute(InvalidRoute)
37 }
38 });
39
40 router.run();
890274a7
BB
41
42</script>
43
890274a7 44<Header />
24be7b53 45<svelte:component this={ page } params={ params } />
890274a7 46<ForumList />