I am using the react-router to pass input data from a search box when the user clicks the search button. However, when I press enter the input doesn't get passed over and the page just refreshes. Is there anyway I could set it so when the enter key is pressed the Nav routing happens?
import React, {useState} from 'react'
import '../sass/custom.scss';
import {Nav, Form, FormControl} from 'react-bootstrap';
import 'bootstrap/dist/css/bootstrap.min.css';
import {NavLink} from 'react-router-dom';
export const SearchBar = () => {
let [query, setQuery] = useState("")
return (
<div className="search-container">
<div className="row height d-flex justify-content-center align-items-center">
<div className="col-xs-12 col-sm-12 col-md-8 col-lg-8 my-5">
<div className="search"> <i className="fa fa-search"></i>
<Form className='d-flex mx-auto'>
<FormControl
type='search'
placeholder='Search'
className='form-control'
aria-label='Search'
onChange={e => setQuery(e.target.value) }
/>
<Nav.Link
as={NavLink}
exact={true}
to={{pathname:`/search`, state: `${query}` }}
className="search-button center btn btn-primary"
>
Search
</Nav.Link>
</Form>
</div>
</div>
</div>
</div>
)
}