File tree Expand file tree Collapse file tree 2 files changed +42
-1
lines changed
Expand file tree Collapse file tree 2 files changed +42
-1
lines changed Original file line number Diff line number Diff line change @@ -232,7 +232,6 @@ See ${createDocumentationLink({
232232 this . _stalledSearchDelay = stalledSearchDelay ;
233233 this . _searchStalledTimer = null ;
234234 this . _isSearchStalled = false ;
235- this . _initialUiState = initialUiState ;
236235
237236 if ( searchFunction ) {
238237 this . _searchFunction = searchFunction ;
@@ -246,6 +245,15 @@ See ${createDocumentationLink({
246245 ...routing ,
247246 } ;
248247 }
248+
249+ if ( this . routing ) {
250+ this . _initialUiState = {
251+ ...initialUiState ,
252+ ...this . routing . stateMapping . routeToState ( this . routing . router . read ( ) ) ,
253+ } ;
254+ } else {
255+ this . _initialUiState = initialUiState ;
256+ }
249257 }
250258
251259 /**
Original file line number Diff line number Diff line change @@ -440,6 +440,39 @@ describe('start', () => {
440440 } ) ;
441441 } ) ;
442442
443+ it ( 'forwards the router state to the main index' , ( ) => {
444+ const router = {
445+ read : jest . fn ( ( ) => ( {
446+ indexName : {
447+ hierarchicalMenu : {
448+ 'hierarchicalCategories.lvl0' : [ 'Cell Phones' ] ,
449+ } ,
450+ } ,
451+ } ) ) ,
452+ write : jest . fn ( ) ,
453+ onUpdate : jest . fn ( ) ,
454+ createURL : jest . fn ( ( ) => '#' ) ,
455+ } ;
456+
457+ const search = new InstantSearch ( {
458+ indexName : 'indexName' ,
459+ searchClient : createSearchClient ( ) ,
460+ routing : {
461+ router,
462+ } ,
463+ } ) ;
464+
465+ search . start ( ) ;
466+
467+ expect ( search . mainIndex . getWidgetState ( ) ) . toEqual ( {
468+ indexName : {
469+ hierarchicalMenu : {
470+ 'hierarchicalCategories.lvl0' : [ 'Cell Phones' ] ,
471+ } ,
472+ } ,
473+ } ) ;
474+ } ) ;
475+
443476 it ( 'calls `init` on the added widgets' , ( ) => {
444477 const search = new InstantSearch ( {
445478 indexName : 'indexName' ,
You can’t perform that action at this time.
0 commit comments