From: Eduardo San Martin Morote Date: Fri, 6 Dec 2024 08:40:16 +0000 (+0100) Subject: refactor: simplify parseURL X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9dcfd423156577a66b50b575781738599c37513b;p=thirdparty%2Fvuejs%2Frouter.git refactor: simplify parseURL --- diff --git a/packages/router/src/location.ts b/packages/router/src/location.ts index e0aa5405..0811c35c 100644 --- a/packages/router/src/location.ts +++ b/packages/router/src/location.ts @@ -52,19 +52,19 @@ export function parseURL( // NOTE: we could use URL and URLSearchParams but they are 2 to 5 times slower than this method const hashPos = location.indexOf('#') - // let searchPos = location.indexOf('?') - let searchPos = - hashPos >= 0 - ? // find the query string before the hash to avoid including a ? in the hash - // e.g. /foo#hash?query -> has no query - location.lastIndexOf('?', hashPos) - : location.indexOf('?') + let searchPos = location.indexOf('?') + + // This ensures that the ? is not part of the hash + // e.g. /foo#hash?query -> has no query + searchPos = hashPos >= 0 && searchPos > hashPos ? -1 : searchPos if (searchPos >= 0) { path = location.slice(0, searchPos) - searchString = - '?' + - location.slice(searchPos + 1, hashPos > 0 ? hashPos : location.length) + // keep the ? char + searchString = location.slice( + searchPos, + hashPos > 0 ? hashPos : location.length + ) query = parseQuery(searchString) } @@ -213,7 +213,7 @@ export function resolveRelativePath(to: string, from: string): string { return to } - // resolve '' with '/anything' -> '/anything' + // resolve to: '' with from: '/anything' -> '/anything' if (!to) return from const fromSegments = from.split('/')