Reactjs 如何摆脱这个?从url

Reactjs 如何摆脱这个?从url,reactjs,url,url-rewriting,url-routing,react-router-dom,Reactjs,Url,Url Rewriting,Url Routing,React Router Dom,我正在制作一个react应用程序,每当我在主页上搜索某个内容(如cat),url都会更改为search/cat,前进、后退按钮正常工作&帮助我在主页和cat搜索页面之间切换……但是当我在(主页->cat)之后再次搜索某个内容(如rat)时,url会更改为search/rat?现在,当我按下后退按钮时,url变为search/rat,我在同一个页面上,如果我再次按下后退按钮,url变为search/cat,但页面仍然有rat搜索的结果,如果我再次按下后退按钮,主页就会出现。为什么会发生这种情况?我

我正在制作一个react应用程序,每当我在主页上搜索某个内容(如cat),url都会更改为search/cat,前进、后退按钮正常工作&帮助我在主页和cat搜索页面之间切换……但是当我在(主页->cat)之后再次搜索某个内容(如rat)时,url会更改为search/rat?现在,当我按下后退按钮时,url变为search/rat,我在同一个页面上,如果我再次按下后退按钮,url变为search/cat,但页面仍然有rat搜索的结果,如果我再次按下后退按钮,主页就会出现。为什么会发生这种情况?我认为这是因为?出现在url末尾的。请帮助

搜猫之后 在寻找老鼠之后 按下后退按钮后 按下后退按钮后 按下后退按钮后

这是搜索栏的代码

import React,{Component}来自“React”;
导入“/styles/searchBar.scss”;
导入“font awesome/css/font awesome.min.css”;
从“react router dom”导入{withRouter};
从“/SearchForm”导入SearchForm;
从“react redux”导入{connect};
从“./redux/actions/randomPhotoAction”导入{fetchRandomPhotos};
类搜索栏扩展组件{
状态={
searchQuery:“”,
};
componentDidMount(){
this.props.fetchRandomPhotos();
}
handleChange=(事件)=>{
this.setState({searchQuery:event.target.value});
};
handleSubmit=(事件)=>{
//event.preventDefault();
this.props.history.push(`/search/${this.state.searchQuery}`);
};
handleProfile=()=>{
this.props.history.push(`/public/${this.props.photo.user.username}`);
};
render(){
const{photo}=this.props;
回来!照片(
福托工厂
互联网上免费使用图像的来源

由无处不在的创造者驱动

) : ( 福托工厂 互联网上免费使用图像的来源

由无处不在的创造者驱动

照片由{“} {photo.user.name}

); } } 常量mapStateToProps=(状态)=>{ 返回{ 照片:state.randomPhotoState.photo, }; }; 导出默认连接(MapStateTops,{fetchRandomPhotos})( withRouter(搜索栏) );
import React,{Component}来自“React”;
导入“/styles/searchBar.scss”;
导入“font awesome/css/font awesome.min.css”;
从“react router dom”导入{withRouter};
从“/SearchForm”导入SearchForm;
从“react redux”导入{connect};
从“./redux/actions/randomPhotoAction”导入{fetchRandomPhotos};
类搜索栏扩展组件{
状态={
searchQuery:“”,
};
componentDidMount(){
this.props.fetchRandomPhotos();
}
handleChange=(事件)=>{
this.setState({searchQuery:event.target.value});
};
handleSubmit=(事件)=>{
event.preventDefault();
if(this.state.searchQuery){
this.props.history.push(`/search/${this.state.searchQuery}`);
}
};
handleProfile=()=>{
this.props.history.push(`/public/${this.props.photo.user.username}`);
};
render(){
const{photo}=this.props;
回来!照片(
福托工厂
互联网上免费使用图像的来源

由无处不在的创造者驱动

) : ( 福托工厂 互联网上免费使用图像的来源

由无处不在的创造者驱动

照片由{“} {photo.user.name}

); } } 常量mapStateToProps=(状态)=>{ 返回{ 照片:state.randomPhotoState.photo, }; }; 导出默认连接(MapStateTops,{fetchRandomPhotos})( withRouter(搜索栏)
);需要更多上下文,请提供code@Joshlucpoll添加了一些代码..截图有用吗?我可以添加它们是的,那很好,你也可以添加组件吗?@Joshlucpoll添加了组件..我正在添加屏幕截图来尝试替换
this.props.history.push(`/search/${this.state.searchQuery}`)带有
window.location.href=`/search/${this.state.searchQuery}`
并查看它是否起作用