@@ -38,10 +38,7 @@ module.exports = app => app.component('document-details', {
3838 }
3939 } ) ;
4040
41- const searchFromUrl = this . getSearchQueryFromRoute ( ) ;
42- if ( searchFromUrl ) {
43- this . searchQuery = searchFromUrl ;
44- }
41+ this . searchQuery = this . getSearchQueryFromRoute ( ) ;
4542 } ,
4643 beforeDestroy ( ) {
4744 this . destroyFieldValueEditor ( ) ;
@@ -262,36 +259,33 @@ module.exports = app => app.component('document-details', {
262259 } ,
263260 methods : {
264261 getSearchQueryFromRoute ( ) {
265- if ( ! this . $route ) {
266- return '' ;
267- }
268- const queryValue = this . $route . query ?. fieldSearch ;
269- if ( typeof queryValue === 'string' ) {
270- return queryValue ;
271- }
272- return '' ;
262+ return this . $route ?. query ?. fieldSearch || '' ;
273263 } ,
274264 syncSearchQueryToUrl ( value ) {
275- if ( ! this . $router || ! this . $route ) {
265+ if ( typeof window === 'undefined' ) {
276266 return ;
277267 }
278268
279269 const normalizedValue = typeof value === 'string' ? value : '' ;
280270 const shouldStore = normalizedValue . trim ( ) . length > 0 ;
281- const currentValue = typeof this . $route . query . fieldSearch === 'string' ? this . $route . query . fieldSearch : '' ;
271+ const hash = window . location . hash . replace ( / ^ # ? / , '' ) ;
272+ const [ hashPath , hashQueryString = '' ] = hash . split ( '?' ) ;
273+ const params = new URLSearchParams ( hashQueryString ) ;
274+ const currentValue = params . get ( 'fieldSearch' ) || '' ;
282275
283276 if ( normalizedValue === currentValue || ( ! shouldStore && ! currentValue ) ) {
284277 return ;
285278 }
286279
287- const nextQuery = { ...this . $route . query } ;
288280 if ( shouldStore ) {
289- nextQuery . fieldSearch = normalizedValue ;
281+ params . set ( ' fieldSearch' , normalizedValue ) ;
290282 } else {
291- delete nextQuery . fieldSearch ;
283+ params . delete ( ' fieldSearch' ) ;
292284 }
293285
294- this . $router . replace ( { query : nextQuery } ) . catch ( ( ) => { } ) ;
286+ const nextQueryString = params . toString ( ) ;
287+ const nextHash = nextQueryString ? `${ hashPath } ?${ nextQueryString } ` : hashPath ;
288+ window . history . replaceState ( window . history . state , '' , `#${ nextHash } ` ) ;
295289 } ,
296290 toggleVirtualField ( fieldName ) {
297291 if ( this . collapsedVirtuals . has ( fieldName ) ) {
0 commit comments