File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -87,6 +87,16 @@ export default {
87
87
flexsearchSvc .buildIndex (this .$site .pages )
88
88
this .placeholder = this .$site .themeConfig .searchPlaceholder || ' '
89
89
document .addEventListener (' keydown' , this .onHotkey )
90
+
91
+ // set query from URL
92
+ const params = this .urlParams ()
93
+ if (params) {
94
+ const query = params .get (' query' )
95
+ if (query) {
96
+ this .query = decodeURI (query)
97
+ this .focused = true
98
+ }
99
+ }
90
100
},
91
101
beforeDestroy () {
92
102
document .removeEventListener (' keydown' , this .onHotkey )
@@ -173,6 +183,16 @@ export default {
173
183
this .$router .push (this .suggestions [i].path + this .suggestions [i].slug )
174
184
this .query = ' '
175
185
this .focusIndex = 0
186
+ this .focused = false
187
+
188
+ // reset query param
189
+ const params = this .urlParams ()
190
+ if (params) {
191
+ params .delete (' query' )
192
+ const paramsString = params .toString ()
193
+ const newState = window .location .pathname + (paramsString ? ` ?${ paramsString} ` : ' ' )
194
+ history .pushState (null , ' ' , newState);
195
+ }
176
196
}
177
197
},
178
198
focus (i ) {
@@ -181,6 +201,12 @@ export default {
181
201
unfocus () {
182
202
this .focusIndex = - 1
183
203
},
204
+ urlParams () {
205
+ if (! window .location .search ) {
206
+ return null
207
+ }
208
+ return new URLSearchParams (window .location .search )
209
+ }
184
210
},
185
211
}
186
212
</script >
You can’t perform that action at this time.
0 commit comments