Pass object to query on Router.push NextJs 1

Pass object to query on Router.push NextJs

import Router, { withRouter } from 'next/router'

performSearch = (event) => {
    Router.push({ pathname: '/results', state: { pattern: this.state.searchText } });

Here is what the above code is Doing:
1. We’re importing the Router object from the next/router package.
2. We’re importing the withRouter HOC from the next/router package.
3. We’re creating a performSearch function that will be called when the user submits the search form.
4. We’re calling the push method on the Router object to navigate to the results page.
5. We’re passing the search pattern as a state object to the results page.

Now, let’s update the SearchForm component to use the performSearch function:

Similar Posts