reactjs - React Router 更改了 URL 但页面仍然没有改变
问题描述
我使用自定义浏览器历史记录进行编程导航。为此,我以这种方式创造了历史:
import { createBrowserHistory } from 'history';
export default createBrowserHistory();
然后我把历史作为道具给了我的路由器,
const App=()=>{
const error=()=>{
return <h1>webpage was not found</h1>
}
return (
<Router history={history}>
<div className="ui container">
<Header/>
<Route path="/" exact component={StreamList}/>
<Route path="/delete/:id" component={StreamDelete}/>
<Route path="/edit/:id" component={StreamEdit}/>
<Route path="/show/:id" component={StreamShow}/>
<Route path="/new" component={StreamCreate}/>
</div>
</Router>
)
}
操作完成后,我使用以下代码将我的应用程序从 StreamCreate 页面强制导航到 StreamList 页面。URL 改变,但页面没有改变。
export const createStream=(values)=>async(dispatch,getState)=>{
const {userId}=getState().auth;
const response=await jsonServer.post("/streams",{...values,userId});
dispatch({type:'CREATE_POST', payload:response.data})
history.push('/')
}
解决方案
推荐阅读
- javascript - 通过 javascript 和 keyevent 从一个 html 页面移动到下一个页面
- c++ - C++、二进制或文本中“ofstream”的默认模式是什么?
- python - 根据用户输入从 python 中的 .txt 文件中提取信息
- python - 熊猫 - 如何重新采样尊重第一次约会?
- c# - Json.Net - 在 c# 中反序列化为枚举
- sql-server - T-SQL 使用变量作为表名
- amazon-s3 - S3 云托管人
- javascript - 通过网站按钮执行无限循环的python脚本不起作用
- python - Python:使用列表推导的最佳方式?
- vue.js - 如果在 Vue.js 中禁用输入,则更改背景颜色