mirror of
https://github.com/flarum/framework.git
synced 2025-05-21 22:36:01 +08:00
Make discussion slug URL parameter optional
This commit is contained in:
@ -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));
|
||||
}
|
||||
|
||||
|
@ -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());
|
||||
};
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user