feat: include query parameters in locale redirect (#6132)

* feat: include query parameters in locale redirect

* refactor: code cleanup

---------

Co-authored-by: Nicolas Giard <github@ngpixel.com>
This commit is contained in:
Dan Nicholson 2023-02-16 17:04:19 -07:00 committed by GitHub
parent 26dcc007e7
commit 78a35c377c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,6 +4,7 @@ const pageHelper = require('../helpers/page')
const _ = require('lodash')
const CleanCSS = require('clean-css')
const moment = require('moment')
const qs = require('querystring')
/* global WIKI */
@ -420,7 +421,8 @@ router.get('/*', async (req, res, next) => {
if (isPage) {
if (WIKI.config.lang.namespacing && !pageArgs.explicitLocale) {
return res.redirect(`/${pageArgs.locale}/${pageArgs.path}`)
const query = !_.isEmpty(req.query) ? `?${qs.stringify(req.query)}` : ''
return res.redirect(`/${pageArgs.locale}/${pageArgs.path}${query}`)
}
req.i18n.changeLanguage(pageArgs.locale)