import { ListenerRemover } from '../types'
-import { RawHistoryQuery, HistoryQuery } from '../utils/query'
+import { LocationQueryRaw, LocationQuery } from '../utils/query'
interface HistoryLocation {
fullPath: string
export type HistoryLocationNormalized = Pick<HistoryLocation, 'fullPath'>
export interface LocationPartial {
path: string
- query?: RawHistoryQuery
+ query?: LocationQueryRaw
hash?: string
}
export interface LocationNormalized {
path: string
fullPath: string
hash: string
- query: HistoryQuery
+ query: LocationQuery
}
// pushState clones the state passed and do not accept everything
* @returns a normalized history location
*/
export function parseURL(
- parseQuery: (search: string) => HistoryQuery,
+ parseQuery: (search: string) => LocationQuery,
location: string
): LocationNormalized {
let path = '',
- query: HistoryQuery = {},
+ query: LocationQuery = {},
searchString = '',
hash = ''
* @param location
*/
export function stringifyURL(
- stringifyQuery: (query: RawHistoryQuery) => string,
+ stringifyQuery: (query: LocationQueryRaw) => string,
location: LocationPartial
): string {
let query: string = location.query ? stringifyQuery(location.query) : ''
-import { HistoryQuery, RawHistoryQuery } from '../utils/query'
+import { LocationQuery, LocationQueryRaw } from '../utils/query'
import { PathParserOptions } from '../matcher/path-parser-ranker'
import { markNonReactive } from 'vue'
import { RouteRecordNormalized } from '../matcher/types'
export type RouteParams = Record<string, string | string[]>
export interface RouteQueryAndHash {
- query?: RawHistoryQuery
+ query?: LocationQueryRaw
hash?: string
}
export interface LocationAsPath {
extends Required<RouteQueryAndHash & LocationAsRelative & LocationAsPath> {
fullPath: string
// the normalized version cannot have numbers or undefined
- query: HistoryQuery
+ query: LocationQuery
// TODO: do the same for params
name: string | null | undefined
matched: RouteRecordNormalized[] // non-enumerable
import { decode, encodeQueryProperty } from '../utils/encoding'
-type HistoryQueryValue = string | null
-type RawHistoryQueryValue = HistoryQueryValue | number | undefined
-export type HistoryQuery = Record<
+type LocationQueryValue = string | null
+type LocationQueryValueRaw = LocationQueryValue | number | undefined
+export type LocationQuery = Record<
string,
- HistoryQueryValue | HistoryQueryValue[]
+ LocationQueryValue | LocationQueryValue[]
>
-export type RawHistoryQuery = Record<
+export type LocationQueryRaw = Record<
string | number,
- RawHistoryQueryValue | RawHistoryQueryValue[]
+ LocationQueryValueRaw | LocationQueryValueRaw[]
>
/**
* @param search
* @returns a query object
*/
-export function parseQuery(search: string): HistoryQuery {
- const query: HistoryQuery = {}
+export function parseQuery(search: string): LocationQuery {
+ const query: LocationQuery = {}
// avoid creating an object with an empty key and empty value
// because of split('&')
if (search === '' || search === '?') return query
* Stringify an object query. Works like URLSearchParams. Doesn't prepend a `?`
* @param query
*/
-export function stringifyQuery(query: RawHistoryQuery): string {
+export function stringifyQuery(query: LocationQueryRaw): string {
let search = ''
for (let key in query) {
if (search.length) search += '&'
continue
}
// keep null values
- let values: RawHistoryQueryValue[] = Array.isArray(value)
+ let values: LocationQueryValueRaw[] = Array.isArray(value)
? value.map(v => v && encodeQueryProperty(v))
: [value && encodeQueryProperty(value)]
* null in arrays
* @param query
*/
-export function normalizeQuery(query: RawHistoryQuery): HistoryQuery {
- const normalizedQuery: HistoryQuery = {}
+export function normalizeQuery(query: LocationQueryRaw): LocationQuery {
+ const normalizedQuery: LocationQuery = {}
for (let key in query) {
let value = query[key]