mirror of
https://github.com/flarum/framework.git
synced 2024-11-29 12:43:52 +08:00
common: remove falsy params when using app.route()
This commit is contained in:
parent
c615fb96c9
commit
e86940b6a3
|
@ -200,6 +200,13 @@ export default abstract class Application {
|
|||
if (!route) throw new Error(`Route '${name}' does not exist`);
|
||||
|
||||
const url = route.path.replace(/:([^\/]+)/g, (m, key) => extract(params, key));
|
||||
|
||||
// Remove falsy values in params to avoid
|
||||
// having urls like '/?sort&q'
|
||||
for (const key in params) {
|
||||
if (params.hasOwnProperty(key) && !params[key]) delete params[key];
|
||||
}
|
||||
|
||||
const queryString = m.buildQueryString(params);
|
||||
const prefix = m.route.prefix === '' ? this.forum.attribute('basePath') : '';
|
||||
|
||||
|
|
|
@ -30,13 +30,11 @@ export default app => {
|
|||
app.route.discussion = (discussion: Discussion, near?: number): string => {
|
||||
const slug = discussion?.slug();
|
||||
const hasNear = near && near !== 1;
|
||||
const params = {
|
||||
|
||||
return app.route(hasNear ? 'discussion.near' : 'discussion', {
|
||||
id: discussion.id() + (slug.trim() ? '-' + slug : ''),
|
||||
};
|
||||
|
||||
if (hasNear) params['near'] = near;
|
||||
|
||||
return app.route(hasNear ? 'discussion.near' : 'discussion', params);
|
||||
near: hasNear && near,
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue
Block a user