@ -125,9 +125,36 @@ export const deserializeState = serializedState => {
return JSON . parse ( decodeURIComponent ( stateString ) )
return JSON . parse ( decodeURIComponent ( stateString ) )
}
}
const getQueryStringObject = query => {
if ( query . state ) {
return deserializeState ( query . state )
}
const state = mapper . map ( readMappings , query )
Object . keys ( state ) . forEach ( key => {
if ( state [ key ] === '' ) state [ key ] = undefined
} )
return state
}
function getQueryStringState ( query ) {
const queryParams = getQueryStringObject ( query )
return Object . keys ( queryParams ) . length ? queryParams : { }
}
function fixAsPathEncoding ( asPath ) {
try {
return url . parse ( asPath , true )
} catch ( e ) {
return url . parse ( encodeURI ( asPath ) , true )
}
}
export const getRouteState = router => {
export const getRouteState = router => {
const { asPath = '' } = router
const { asPath = '' } = router
const { query , pathname } = url . parse ( asPath , true )
const { query , pathname } = fixAsPathEncoding( asPath )
const queryState = getQueryStringState ( query )
const queryState = getQueryStringState ( query )
const path = escapeHtml (
const path = escapeHtml (
pathname
pathname
@ -161,22 +188,3 @@ export const updateRouteState = (router, state) => {
{ shallow : true }
{ shallow : true }
)
)
}
}
const getQueryStringObject = query => {
if ( query . state ) {
return deserializeState ( query . state )
}
const state = mapper . map ( readMappings , query )
Object . keys ( state ) . forEach ( key => {
if ( state [ key ] === '' ) state [ key ] = undefined
} )
return state
}
function getQueryStringState ( query ) {
const queryParams = getQueryStringObject ( query )
return Object . keys ( queryParams ) . length ? queryParams : { }
}