Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow routing without a search box (regular JS / non-react version) #4129

Closed
t0byman opened this issue Sep 18, 2019 · 2 comments
Closed

Allow routing without a search box (regular JS / non-react version) #4129

t0byman opened this issue Sep 18, 2019 · 2 comments

Comments

@t0byman
Copy link

t0byman commented Sep 18, 2019

Is your feature request related to a problem? Please describe πŸ™
No.

Describe the solution you'd like πŸ€”
I would like to be able to do routing without having a search box on my page.

Describe alternatives you've considered ✨
I added routing using the parseURL method. It works great, but only when I have a search box on my page. This is because of const { query = queryName } = qsModule.parse( location.search.slice(1) ); the location.search part is telling the query to go into the search box so that my results can be filtered. But I want them to be filtered without a search box, when the page loads. Is this possible? If not, here is my feature request :)

Additional context
Here is my complete routing code:

routing: {
                router: instantsearch.routers.history({
                    parseURL({ qsModule, location }) {
                        const pathnameMatches = location.pathname.match(/zoeken\/(.*?)\/?$/);
                        const queryName = getQueryName(
                            (pathnameMatches && pathnameMatches[1]) || ''
                        );
                        const { query = queryName } = qsModule.parse(
                            location.search.slice(1)
                        );

                        return {
                            query: decodeURIComponent(query),
                        };
                    }
                }),

                stateMapping: {
                    stateToRoute(uiState) {
                        return {
                            query: uiState.query,
                        };
                    },

                    routeToState(routeState) {
                        return {
                            query: routeState.query,
                        };
                    }
                }
            }
@francoischalifour
Copy link
Member

Mounting a search box widget on the page is necessary for the query search parameter to be sent to Algolia. Widgets drive search parameters.

You don't have to display a search box though, you can create a virtual widget without rendering with connectSearchBox.

@t0byman
Copy link
Author

t0byman commented Sep 19, 2019

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants