parseURL as originalParseURL,
stringifyURL as originalStringifyURL,
stripBase,
- isSameLocationObject,
+ isSameRouteLocationParams,
} from '../src/location'
describe('parseURL', () => {
})
})
-describe('isSameLocationObject', () => {
+describe('isSameRouteLocationParams', () => {
it('compare simple values', () => {
- expect(isSameLocationObject({ a: '2' }, { a: '2' })).toBe(true)
- expect(isSameLocationObject({ a: '3' }, { a: '2' })).toBe(false)
+ expect(isSameRouteLocationParams({ a: '2' }, { a: '2' })).toBe(true)
+ expect(isSameRouteLocationParams({ a: '3' }, { a: '2' })).toBe(false)
// different order
- expect(isSameLocationObject({ a: '2', b: '3' }, { b: '3', a: '2' })).toBe(
- true
- )
- expect(isSameLocationObject({ a: '3', b: '3' }, { b: '3', a: '2' })).toBe(
- false
- )
+ expect(
+ isSameRouteLocationParams({ a: '2', b: '3' }, { b: '3', a: '2' })
+ ).toBe(true)
+ expect(
+ isSameRouteLocationParams({ a: '3', b: '3' }, { b: '3', a: '2' })
+ ).toBe(false)
})
it('compare array values', () => {
- expect(isSameLocationObject({ a: ['2'] }, { a: ['2'] })).toBe(true)
- expect(isSameLocationObject({ a: ['3'] }, { a: ['2'] })).toBe(false)
+ expect(isSameRouteLocationParams({ a: ['2'] }, { a: ['2'] })).toBe(true)
+ expect(isSameRouteLocationParams({ a: ['3'] }, { a: ['2'] })).toBe(false)
// different order
expect(
- isSameLocationObject({ a: ['2'], b: ['3'] }, { b: ['3'], a: ['2'] })
+ isSameRouteLocationParams({ a: ['2'], b: ['3'] }, { b: ['3'], a: ['2'] })
).toBe(true)
expect(
- isSameLocationObject({ a: ['3'], b: ['3'] }, { b: ['3'], a: ['2'] })
+ isSameRouteLocationParams({ a: ['3'], b: ['3'] }, { b: ['3'], a: ['2'] })
).toBe(false)
})
it('considers arrays of one item same as the item itself', () => {
- expect(isSameLocationObject({ a: ['2'] }, { a: '2' })).toBe(true)
- expect(isSameLocationObject({ a: ['3'] }, { a: '2' })).toBe(false)
+ expect(isSameRouteLocationParams({ a: ['2'] }, { a: '2' })).toBe(true)
+ expect(isSameRouteLocationParams({ a: ['3'] }, { a: '2' })).toBe(false)
})
})
VNodeProps,
} from 'vue'
import { RouteLocationRaw, VueUseOptions, RouteLocation } from './types'
-import { isSameLocationObject, isSameRouteRecord } from './location'
+import { isSameRouteLocationParams, isSameRouteRecord } from './location'
import { routerKey, routeLocationKey } from './injectionSymbols'
import { RouteRecord } from './matcher/types'
import { assign } from './utils'
() =>
activeRecordIndex.value > -1 &&
activeRecordIndex.value === currentRoute.matched.length - 1 &&
- isSameLocationObject(currentRoute.params, route.value.params)
+ isSameRouteLocationParams(currentRoute.params, route.value.params)
)
function navigate(e: MouseEvent = {} as MouseEvent): Promise<any> {
aLastIndex > -1 &&
aLastIndex === bLastIndex &&
isSameRouteRecord(a.matched[aLastIndex], b.matched[bLastIndex]) &&
- isSameLocationObject(a.params, b.params) &&
- isSameLocationObject(a.query, b.query) &&
+ isSameRouteLocationParams(a.params, b.params) &&
+ isSameRouteLocationParams(a.query, b.query) &&
a.hash === b.hash
)
}
return (a.aliasOf || a) === (b.aliasOf || b)
}
-export function isSameLocationObject(
+export function isSameRouteLocationParams(
a: RouteLocationNormalized['query'],
b: RouteLocationNormalized['query']
): boolean
-export function isSameLocationObject(
+export function isSameRouteLocationParams(
a: RouteLocationNormalized['params'],
b: RouteLocationNormalized['params']
): boolean
-export function isSameLocationObject(
+export function isSameRouteLocationParams(
a: RouteLocationNormalized['query' | 'params'],
b: RouteLocationNormalized['query' | 'params']
): boolean {
if (Object.keys(a).length !== Object.keys(b).length) return false
for (let key in a) {
- if (!isSameLocationObjectValue(a[key], b[key])) return false
+ if (!isSameRouteLocationParamsValue(a[key], b[key])) return false
}
return true
}
-function isSameLocationObjectValue(
+function isSameRouteLocationParamsValue(
a: LocationQueryValue | LocationQueryValue[],
b: LocationQueryValue | LocationQueryValue[]
): boolean
-function isSameLocationObjectValue(
+function isSameRouteLocationParamsValue(
a: RouteParamValue | RouteParamValue[],
b: RouteParamValue | RouteParamValue[]
): boolean
-function isSameLocationObjectValue(
+function isSameRouteLocationParamsValue(
a:
| LocationQueryValue
| LocationQueryValue[]