2015-07-15 12:30:11 +08:00
|
|
|
import IndexPage from 'flarum/components/IndexPage';
|
|
|
|
import DiscussionPage from 'flarum/components/DiscussionPage';
|
|
|
|
import ActivityPage from 'flarum/components/ActivityPage';
|
|
|
|
import SettingsPage from 'flarum/components/SettingsPage';
|
|
|
|
import NotificationsPage from 'flarum/components/NotificationsPage';
|
2015-04-25 20:58:39 +08:00
|
|
|
|
2015-07-15 12:30:11 +08:00
|
|
|
/**
|
|
|
|
* The `routes` initializer defines the forum app's routes.
|
|
|
|
*
|
|
|
|
* @param {App} app
|
|
|
|
*/
|
2015-04-25 20:58:39 +08:00
|
|
|
export default function(app) {
|
|
|
|
app.routes = {
|
2015-07-15 12:30:11 +08:00
|
|
|
'index': { path: '/', component: IndexPage.component() },
|
|
|
|
'index.filter': { path: '/:filter', component: IndexPage.component() },
|
2015-04-25 20:58:39 +08:00
|
|
|
|
2015-07-15 12:30:11 +08:00
|
|
|
'discussion': { path: '/d/:id/:slug', component: DiscussionPage.component() },
|
|
|
|
'discussion.near': { path: '/d/:id/:slug/:near', component: DiscussionPage.component() },
|
2015-04-25 20:58:39 +08:00
|
|
|
|
2015-07-15 12:30:11 +08:00
|
|
|
'user': { path: '/u/:username', component: ActivityPage.component() },
|
|
|
|
'user.activity': { path: '/u/:username', component: ActivityPage.component() },
|
|
|
|
'user.discussions': { path: '/u/:username/discussions', component: ActivityPage.component({filter: 'startedDiscussion'}) },
|
|
|
|
'user.posts': { path: '/u/:username/posts', component: ActivityPage.component({filter: 'posted'}) },
|
2015-04-25 20:58:39 +08:00
|
|
|
|
2015-07-15 12:30:11 +08:00
|
|
|
'settings': { path: '/settings', component: SettingsPage.component() },
|
|
|
|
'notifications': { path: '/notifications', component: NotificationsPage.component() }
|
2015-04-25 20:58:39 +08:00
|
|
|
};
|
2015-05-14 20:52:36 +08:00
|
|
|
|
2015-07-15 12:30:11 +08:00
|
|
|
/**
|
|
|
|
* Generate a URL to a discussion.
|
|
|
|
*
|
|
|
|
* @param {Discussion} discussion
|
|
|
|
* @param {Integer} [near]
|
|
|
|
* @return {String}
|
|
|
|
*/
|
|
|
|
app.route.discussion = (discussion, near) => {
|
2015-05-14 20:52:36 +08:00
|
|
|
return app.route(near ? 'discussion.near' : 'discussion', {
|
|
|
|
id: discussion.id(),
|
|
|
|
slug: discussion.slug(),
|
|
|
|
near: near
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-07-15 12:30:11 +08:00
|
|
|
/**
|
|
|
|
* Generate a URL to a post.
|
|
|
|
*
|
|
|
|
* @param {Post} post
|
|
|
|
* @return {String}
|
|
|
|
*/
|
|
|
|
app.route.post = post => {
|
2015-05-14 20:52:36 +08:00
|
|
|
return app.route('discussion.near', {
|
|
|
|
id: post.discussion().id(),
|
|
|
|
slug: post.discussion().slug(),
|
|
|
|
near: post.number()
|
|
|
|
});
|
|
|
|
};
|
2015-05-26 16:32:04 +08:00
|
|
|
|
2015-07-15 12:30:11 +08:00
|
|
|
/**
|
|
|
|
* Generate a URL to a user.
|
|
|
|
*
|
|
|
|
* @param {User} user
|
|
|
|
* @return {String}
|
|
|
|
*/
|
|
|
|
app.route.user = user => {
|
2015-05-26 16:32:04 +08:00
|
|
|
return app.route('user', {
|
|
|
|
username: user.username()
|
|
|
|
});
|
|
|
|
};
|
2015-04-25 20:58:39 +08:00
|
|
|
}
|