Make discussion slug URL parameter optional

This commit is contained in:
Toby Zerner
2015-08-25 19:32:41 +09:30
parent b49b3a14b4
commit b8fc0bc376
4 changed files with 10 additions and 14 deletions

View File

@ -62,7 +62,9 @@ export default class DiscussionPage extends mixin(Component, evented) {
// cancel the unloading of this controller and instead prompt the post
// stream to jump to the new 'near' param.
if (this.discussion) {
if (m.route.param('id') === this.discussion.id()) {
const idParam = m.route.param('id');
if (idParam && idParam.split('-')[0] === this.discussion.id()) {
e.preventDefault();
const near = Number(m.route.param('near')) || 1;
@ -143,7 +145,7 @@ export default class DiscussionPage extends mixin(Component, evented) {
} else {
const params = this.requestParams();
app.store.find('discussions', m.route.param('id'), params)
app.store.find('discussions', m.route.param('id').split('-')[0], params)
.then(this.init.bind(this));
}

View File

@ -15,9 +15,8 @@ export default function(app) {
'index': {path: '/all', component: IndexPage.component()},
'index.filter': {path: '/:filter', component: IndexPage.component()},
'discussion.id': {path: '/d/:id', component: DiscussionPage.component()},
'discussion': {path: '/d/:id/:slug', component: DiscussionPage.component()},
'discussion.near': {path: '/d/:id/:slug/:near', component: DiscussionPage.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()},
@ -36,8 +35,7 @@ export default function(app) {
*/
app.route.discussion = (discussion, near) => {
return app.route(near > 1 ? 'discussion.near' : 'discussion', {
id: discussion.id(),
slug: discussion.slug(),
id: discussion.id() + '-' + discussion.slug(),
near: near > 1 ? near : undefined
});
};
@ -49,11 +47,7 @@ export default function(app) {
* @return {String}
*/
app.route.post = post => {
return app.route('discussion.near', {
id: post.discussion().id(),
slug: post.discussion().slug(),
near: post.number()
});
return app.route.discussion(post.discussion(), post.number());
};
/**