Reactjs 使用useHistory钩子重定向到具有不同查询参数的特定url

Reactjs 使用useHistory钩子重定向到具有不同查询参数的特定url,reactjs,react-router,Reactjs,React Router,我正在使用ant-d搜索栏获取查询值并重定向到URL,但不知何故它似乎不起作用 我是一个新的反应和反应路由器 我试过了 import { React, useState } from 'react' import { Input } from 'antd'; import {useHistory } from 'react-router-dom'; const { Search } = Input; function SearchBar() { const [query, setQu

我正在使用ant-d搜索栏获取查询值并重定向到URL,但不知何故它似乎不起作用

我是一个新的反应和反应路由器

我试过了

import { React, useState } from 'react'
import { Input } from 'antd';
import {useHistory } from 'react-router-dom';

const { Search } = Input;

function SearchBar() {
    const [query, setQuery] = useState("");
    const history = useHistory();
    const onSearch = value => {
            setQuery(value);
            let queryString = "q=" + query;
            history.push(`https://link?${queryString}`);
    }
    return (
        <div>
            <p className="font-sans text-gray-700 font-semi-bold text-lg pb-6"> Help and Support</p>
            <Search placeholder="input search text" onSearch={onSearch} enterButton />
        </div>
    )
}

export default SearchBar;


从'React'导入{React,useState}
从“antd”导入{Input};
从'react router dom'导入{useHistory};
const{Search}=输入;
函数搜索栏(){
const[query,setQuery]=useState(“”);
const history=useHistory();
const onSearch=值=>{
setQuery(值);
让queryString=“q=”+查询;
历史推送(`https://link?${queryString}`);
}
返回(
帮助和支持

) } 导出默认搜索栏;
我错过什么了吗

错误: 未捕获类型错误:无法读取未定义的属性“push”

 10 | const onSearch = value => {
  11 |         setQuery(value);
  12 |         let queryString = "q=" + query;
> 13 |         history.push(`https://link?${queryString}`);
     | ^  14 | }
  15 | return (
  16 |     <div>

10 | const onSearch=value=>{
11 |设置查询(值);
12 |让queryString=“q=”+查询;
>13 | history.push(`https://link?${queryString}`);
| ^  14 | }
15 |返回(
16 |     

尝试按如下方式声明函数,从中可以获得“history”属性:

export const SearchBar= ({history}) => {
 ...your code
}

你的应用程序是否使用了
BrowserRouter
?@BadalSaibo否,在我更改后,还有一个问题是将新链接附加到现有链接。如何在新选项卡中打开?请改用窗口对象,
window.open(“/some link”,“_blank”);