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>
pull/6185/head
Dan Nicholson 2 years ago committed by GitHub
parent 26dcc007e7
commit 78a35c377c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -4,6 +4,7 @@ const pageHelper = require('../helpers/page')
const _ = require('lodash') const _ = require('lodash')
const CleanCSS = require('clean-css') const CleanCSS = require('clean-css')
const moment = require('moment') const moment = require('moment')
const qs = require('querystring')
/* global WIKI */ /* global WIKI */
@ -420,7 +421,8 @@ router.get('/*', async (req, res, next) => {
if (isPage) { if (isPage) {
if (WIKI.config.lang.namespacing && !pageArgs.explicitLocale) { 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) req.i18n.changeLanguage(pageArgs.locale)

Loading…
Cancel
Save