stringifyURL as originalStringifyURL,
stripBase,
isSameRouteLocationParams,
+ isSameRouteLocation,
} from '../src/location'
+import { RouteLocationNormalizedLoaded } from 'src'
describe('parseURL', () => {
let parseURL = originalParseURL.bind(null, parseQuery)
expect(isSameRouteLocationParams({ a: ['3'] }, { a: '2' })).toBe(false)
})
})
+
+describe('isSameRouteLocation', () => {
+ it('compares queries as strings', () => {
+ const location: RouteLocationNormalizedLoaded = {
+ path: '/',
+ params: {},
+ name: 'home',
+ matched: [{} as any],
+ fullPath: '/',
+ hash: '',
+ meta: {},
+ query: {},
+ redirectedFrom: undefined,
+ }
+ expect(
+ isSameRouteLocation(
+ () => 'fake query',
+ { ...location, query: { a: 'a' } },
+ { ...location, query: { b: 'b' } }
+ )
+ ).toBe(true)
+ })
+})
-import { LocationQuery, LocationQueryRaw, LocationQueryValue } from './query'
+import { LocationQuery, LocationQueryRaw } from './query'
import {
RouteLocation,
RouteLocationNormalized,
* @param b second {@link RouteLocation}
*/
export function isSameRouteLocation(
+ stringifyQuery: (query: LocationQueryRaw) => string,
a: RouteLocation,
b: RouteLocation
): boolean {
aLastIndex === bLastIndex &&
isSameRouteRecord(a.matched[aLastIndex], b.matched[bLastIndex]) &&
isSameRouteLocationParams(a.params, b.params) &&
- isSameRouteLocationParams(a.query, b.query) &&
+ stringifyQuery(a.query) === stringifyQuery(b.query) &&
a.hash === b.hash
)
}
return (a.aliasOf || a) === (b.aliasOf || b)
}
-export function isSameRouteLocationParams(
- a: RouteLocationNormalized['query'],
- b: RouteLocationNormalized['query']
-): boolean
export function isSameRouteLocationParams(
a: RouteLocationNormalized['params'],
b: RouteLocationNormalized['params']
-): boolean
-export function isSameRouteLocationParams(
- a: RouteLocationNormalized['query' | 'params'],
- b: RouteLocationNormalized['query' | 'params']
): boolean {
if (Object.keys(a).length !== Object.keys(b).length) return false
return true
}
-function isSameRouteLocationParamsValue(
- a: LocationQueryValue | LocationQueryValue[],
- b: LocationQueryValue | LocationQueryValue[]
-): boolean
function isSameRouteLocationParamsValue(
a: RouteParamValue | RouteParamValue[],
b: RouteParamValue | RouteParamValue[]
-): boolean
-function isSameRouteLocationParamsValue(
- a:
- | LocationQueryValue
- | LocationQueryValue[]
- | RouteParamValue
- | RouteParamValue[],
- b:
- | LocationQueryValue
- | LocationQueryValue[]
- | RouteParamValue
- | RouteParamValue[]
): boolean {
return Array.isArray(a)
? isEquivalentArray(a, b)
toLocation.redirectedFrom = redirectedFrom
let failure: NavigationFailure | void | undefined
- if (!force && isSameRouteLocation(from, targetLocation)) {
+ if (!force && isSameRouteLocation(stringifyQuery, from, targetLocation)) {
failure = createRouterError<NavigationFailure>(
ErrorTypes.NAVIGATION_DUPLICATED,
{ to: toLocation, from }