]> git.r.bdr.sh - rbdr/forum/blob - app/forum.svelte
038f17665ca8ed35876fad6063b4a5262b4384ce
[rbdr/forum] / app / forum.svelte
1 <script>
2 import LightRouter from 'lightrouter';
3
4 import ForumList from './components/forum_list/forum_list.svelte';
5 import Header from './components/header/header.svelte';
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';
12 import Topic from './components/topic/topic.svelte';
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();
41
42 </script>
43
44 <Header />
45 <svelte:component this={ page } params={ params } />
46 <ForumList />