You’re reading the documentation for Vue InstantSearch v4.
Read the migration guide to learn how to upgrade from v3 to v4.
You can still find the v3 documentation for this page.
- Request search results from Algolia
- Render the Vue app with the results of the request
- Store the search results in the page
- Return the HTML page as a string
- Read the search results from the page
- Render (or hydrate) the Vue app with the search results
With Vue CLI
Create Vue app with SSR plugin
Use the Vue CLI to create the app and add the SSR plugin:
Install Vue InstantSearch
Add modules to configuration
Vue InstantSearch uses ES modules, but the app runs on the server, with Node.js.
That’s why you need to add these modules to the At this point, Vue.js renders the app on the server.
But when you go to
vue.config.js configuration file:JavaScript
/search in your browser, you won’t see the search results on the page.
That’s because, by default, Vue InstantSearch starts searching and showing results after the page is rendered for the first time.Create a backend instance
To perform searches on the backend as well, you need to create a backend instance in The Vue app can now inject the backend instance of Vue InstantSearch.
src/main.js:Replace InstantSearch with SSR InstantSearch
In the main file, replace
ais-instant-search with ais-instant-search-ssr.
You can also remove its props since they’re now passed to the createServerRootMixin function.Vue
Add the InstantSearch state
To save the results on the backend, add the InstantSearch state to the
context using the getState function:JavaScript
With Nuxt 2
The following section describes how to set up server-side rendering with Vue InstantSearch and Nuxt 2. Check the community for solutions for Nuxt 3.Create Nuxt app with Vue InstantSearch
Create a Nuxt app and add
vue-instantsearch:Add modules to configuratio
Vue InstantSearch uses ES modules, but the app runs on the server, with Node.js.
That’s why you need to add these modules to the
nuxt.config.js configuration file:JavaScript
Build a search interface
Create a new page
pages/search.vue and build a Vue InstantSearch interface:Vue
Configure Vue InstantSearch for SSR
- Add
createServerRootMixinto create a reusable search instance. - Add
findResultsStateinserverPrefetchto perform a search query in the backend. - Call the
hydratemethod inbeforeMount. - Replace
ais-instant-searchwithais-instant-search-ssr