【发布时间】:2016-10-10 18:32:59
【问题描述】:
我使用以下代码更改我的 React Router 路径:
import React from 'react';
import ReactDOM from 'react-dom';
import classNames from 'classnames';
import { Router, Route, browserHistory, IndexRoute } from 'react-router'
var currentRouteName = this.props.location.pathname;
const path = currentRouteName + '/yes';
browserHistory.push(path);
路由器如下所示:
ReactDOM.render((
<Router history={browserHistory}>
<Route path="/review/request/:id">
<IndexRoute component={QuestionBox}/>
<Route path="yes" component={PositiveBox}/>
<Route path="no" component={NegativeBox}/>
<Route path="thank-you" component={ThankYouComponent}/>
</Route>
</Router>
), document.getElementById('parent-div'))
当我使用上面的代码更改路径时,我的 URL 中会出现一个井号 #,即http://localhost:8080/review/request/5066549580791808/yes#
当我在浏览器中单击返回时,哈希将消失并给我路径:http://localhost:8080/review/request/5066549580791808/yes
但是视图不会更新,如果我再次回击,它会回到根路径:
http://localhost:8080/review/request/5066549580791808
并且视图将再次更改 IndexRoute。我的想法和我希望发生的事情是只需要按一次后退按钮。
谁能告诉我我做错了什么?谢谢!
【问题讨论】:
标签: reactjs react-router