/
routes.js
65 lines (58 loc) · 1.99 KB
/
routes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import IndexPage from './components/IndexPage';
import DiscussionPage from './components/DiscussionPage';
import PostsUserPage from './components/PostsUserPage';
import DiscussionsUserPage from './components/DiscussionsUserPage';
import SettingsPage from './components/SettingsPage';
import NotificationsPage from './components/NotificationsPage';
/**
* The `routes` initializer defines the forum app's routes.
*
* @param {App} app
*/
export default function(app) {
app.routes = {
'index': {path: '/all', component: IndexPage.component()},
'index.filter': {path: '/:filter', component: IndexPage.component()},
'discussion': {path: '/d/:id', component: DiscussionPage.component()},
'discussion.near': {path: '/d/:id/:near', component: DiscussionPage.component()},
'user': {path: '/u/:username', component: PostsUserPage.component()},
'user.posts': {path: '/u/:username', component: PostsUserPage.component()},
'user.discussions': {path: '/u/:username/discussions', component: DiscussionsUserPage.component()},
'settings': {path: '/settings', component: SettingsPage.component()},
'notifications': {path: '/notifications', component: NotificationsPage.component()}
};
/**
* Generate a URL to a discussion.
*
* @param {Discussion} discussion
* @param {Integer} [near]
* @return {String}
*/
app.route.discussion = (discussion, near) => {
const slug = discussion.slug();
return app.route(near && near !== 1 ? 'discussion.near' : 'discussion', {
id: discussion.id() + (slug.trim() ? '-' + slug : ''),
near: near && near !== 1 ? near : undefined
});
};
/**
* Generate a URL to a post.
*
* @param {Post} post
* @return {String}
*/
app.route.post = post => {
return app.route.discussion(post.discussion(), post.number());
};
/**
* Generate a URL to a user.
*
* @param {User} user
* @return {String}
*/
app.route.user = user => {
return app.route('user', {
username: user.username()
});
};
}