mirror of
https://github.com/flarum/framework.git
synced 2025-05-23 23:29:57 +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
|
// cancel the unloading of this controller and instead prompt the post
|
||||||
// stream to jump to the new 'near' param.
|
// stream to jump to the new 'near' param.
|
||||||
if (this.discussion) {
|
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();
|
e.preventDefault();
|
||||||
|
|
||||||
const near = Number(m.route.param('near')) || 1;
|
const near = Number(m.route.param('near')) || 1;
|
||||||
@ -143,7 +145,7 @@ export default class DiscussionPage extends mixin(Component, evented) {
|
|||||||
} else {
|
} else {
|
||||||
const params = this.requestParams();
|
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));
|
.then(this.init.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,9 +15,8 @@ export default function(app) {
|
|||||||
'index': {path: '/all', component: IndexPage.component()},
|
'index': {path: '/all', component: IndexPage.component()},
|
||||||
'index.filter': {path: '/:filter', component: IndexPage.component()},
|
'index.filter': {path: '/:filter', component: IndexPage.component()},
|
||||||
|
|
||||||
'discussion.id': {path: '/d/:id', component: DiscussionPage.component()},
|
'discussion': {path: '/d/:id', component: DiscussionPage.component()},
|
||||||
'discussion': {path: '/d/:id/:slug', component: DiscussionPage.component()},
|
'discussion.near': {path: '/d/:id/:near', component: DiscussionPage.component()},
|
||||||
'discussion.near': {path: '/d/:id/:slug/:near', component: DiscussionPage.component()},
|
|
||||||
|
|
||||||
'user': {path: '/u/:username', component: PostsUserPage.component()},
|
'user': {path: '/u/:username', component: PostsUserPage.component()},
|
||||||
'user.posts': {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) => {
|
app.route.discussion = (discussion, near) => {
|
||||||
return app.route(near > 1 ? 'discussion.near' : 'discussion', {
|
return app.route(near > 1 ? 'discussion.near' : 'discussion', {
|
||||||
id: discussion.id(),
|
id: discussion.id() + '-' + discussion.slug(),
|
||||||
slug: discussion.slug(),
|
|
||||||
near: near > 1 ? near : undefined
|
near: near > 1 ? near : undefined
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -49,11 +47,7 @@ export default function(app) {
|
|||||||
* @return {String}
|
* @return {String}
|
||||||
*/
|
*/
|
||||||
app.route.post = post => {
|
app.route.post = post => {
|
||||||
return app.route('discussion.near', {
|
return app.route.discussion(post.discussion(), post.number());
|
||||||
id: post.discussion().id(),
|
|
||||||
slug: post.discussion().slug(),
|
|
||||||
near: post.number()
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -16,7 +16,7 @@ class DiscussionAction extends ClientAction
|
|||||||
$page = max(1, array_get($queryParams, 'page'));
|
$page = max(1, array_get($queryParams, 'page'));
|
||||||
|
|
||||||
$params = [
|
$params = [
|
||||||
'id' => array_get($routeParams, 'id'),
|
'id' => (int) array_get($routeParams, 'id'),
|
||||||
'page' => [
|
'page' => [
|
||||||
'near' => array_get($routeParams, 'near'),
|
'near' => array_get($routeParams, 'near'),
|
||||||
'offset' => ($page - 1) * 20,
|
'offset' => ($page - 1) * 20,
|
||||||
|
@ -57,7 +57,7 @@ class ForumServiceProvider extends ServiceProvider
|
|||||||
);
|
);
|
||||||
|
|
||||||
$routes->get(
|
$routes->get(
|
||||||
'/d/{id:\d+}[/{slug}[/{near}]]',
|
'/d/{id:\d+(?:-[^/]*)?}[/{near}]',
|
||||||
'flarum.forum.discussion',
|
'flarum.forum.discussion',
|
||||||
$this->action('Flarum\Forum\Actions\DiscussionAction')
|
$this->action('Flarum\Forum\Actions\DiscussionAction')
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user