我使用来自HashRouter
react-router-dom
import {HashRouter, Route, Link} from 'react-router-dom';
<HashRouter>
<div className="container">
<NavBar/>
<Route path="/p1" component={C1}/>
<Route path="/p2" component={C2}/>
<Route path="/p3" component={C3}/>
</div>
</HashRouter>
和Redux商店
<Provider store={store}>
<App/>
</Provider>, document.getElementById('content')
在通过redux函数提交帖子请求时,浏览器中的哈希值将被删除,我将返回/
。
export const postEntitiy= entitiy=> (dispatch, getState) => {
return fetch('/entity/save/', {
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
method: "POST",
body: JSON.stringify(product)
})
.then(response => response.json())
.then(json => dispatch(saveEntityOk(json)));
};
此处所需的行为不会重定向。服务器端只返回正常的json。