diff --git a/packages/next/client/page-loader.ts b/packages/next/client/page-loader.ts index 49d63a6f465aab..700d22d632d802 100644 --- a/packages/next/client/page-loader.ts +++ b/packages/next/client/page-loader.ts @@ -12,7 +12,6 @@ import { import getAssetPathFromRoute from '../next-server/lib/router/utils/get-asset-path-from-route' import { isDynamicRoute } from '../next-server/lib/router/utils/is-dynamic' import { parseRelativeUrl } from '../next-server/lib/router/utils/parse-relative-url' -import { searchParamsToUrlQuery } from '../next-server/lib/router/utils/querystring' export const looseToArray = (input: any): T[] => [].slice.call(input) @@ -204,10 +203,7 @@ export default class PageLoader { * @param {string} asPath the URL as shown in browser (virtual path); used for dynamic routes */ getDataHref(href: string, asPath: string, ssg: boolean) { - const { pathname: hrefPathname, searchParams, search } = parseRelativeUrl( - href - ) - const query = searchParamsToUrlQuery(searchParams) + const { pathname: hrefPathname, query, search } = parseRelativeUrl(href) const { pathname: asPathname } = parseRelativeUrl(asPath) const route = normalizeRoute(hrefPathname) diff --git a/packages/next/next-server/lib/router/router.ts b/packages/next/next-server/lib/router/router.ts index 8843df68d9c971..b0e758dd69a02c 100644 --- a/packages/next/next-server/lib/router/router.ts +++ b/packages/next/next-server/lib/router/router.ts @@ -563,7 +563,7 @@ export default class Router implements BaseRouter { let parsed = parseRelativeUrl(url) - let { pathname, searchParams } = parsed + let { pathname, query } = parsed parsed = this._resolveHref(parsed, pages) as typeof parsed @@ -572,8 +572,6 @@ export default class Router implements BaseRouter { url = formatWithValidation(parsed) } - const query = searchParamsToUrlQuery(searchParams) - // url and as should always be prefixed with basePath by this // point by either next/link or router.push/replace so strip the // basePath from the pathname to match the pages dir 1-to-1 diff --git a/packages/next/next-server/lib/router/utils/parse-relative-url.ts b/packages/next/next-server/lib/router/utils/parse-relative-url.ts index 6475ea6630fa5a..a254613f0164f6 100644 --- a/packages/next/next-server/lib/router/utils/parse-relative-url.ts +++ b/packages/next/next-server/lib/router/utils/parse-relative-url.ts @@ -1,4 +1,5 @@ import { getLocationOrigin } from '../../utils' +import { searchParamsToUrlQuery } from './querystring' const DUMMY_BASE = new URL( typeof window === 'undefined' ? 'http://n' : getLocationOrigin() @@ -29,7 +30,7 @@ export function parseRelativeUrl(url: string, base?: string) { } return { pathname, - searchParams, + query: searchParamsToUrlQuery(searchParams), search, hash, href: href.slice(DUMMY_BASE.origin.length), diff --git a/packages/next/next-server/lib/router/utils/prepare-destination.ts b/packages/next/next-server/lib/router/utils/prepare-destination.ts index 6b43db75afa234..054ece187882f2 100644 --- a/packages/next/next-server/lib/router/utils/prepare-destination.ts +++ b/packages/next/next-server/lib/router/utils/prepare-destination.ts @@ -35,7 +35,7 @@ export default function prepareDestination( parsedDestination = { pathname, - searchParams, + query: searchParamsToUrlQuery(searchParams), hash, protocol, hostname, @@ -45,9 +45,6 @@ export default function prepareDestination( } } - parsedDestination.query = searchParamsToUrlQuery( - parsedDestination.searchParams - ) const destQuery = parsedDestination.query const destPath = `${parsedDestination.pathname!}${ parsedDestination.hash || '' @@ -108,7 +105,6 @@ export default function prepareDestination( parsedDestination.pathname = pathname parsedDestination.hash = `${hash ? '#' : ''}${hash || ''}` delete parsedDestination.search - delete parsedDestination.searchParams } catch (err) { if (err.message.match(/Expected .*? to not repeat, but got an array/)) { throw new Error(