浏览器重置帖子上的哈希路由

时间:2017-04-17 12:47:25

标签: javascript reactjs react-router react-redux fetch-api

我使用来自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。

0 个答案:

没有答案
相关问题