多路由切换使用react-router history api,在android 4.4版本及以上以及ios上均表现正常,但是在andriod 4.3及以下就会出现异常。具体情况如下图:
以上模拟history历史记录的堆栈,replace使用向下箭头,表示替换,push使用横向箭头,表示进入。
在4.4及以上,但使用go(-1)/goBack()
时,会从/path4
返回到/path3
,表现正常;
在4.3及以下,使用go(-1)/goBack()
时,会返回到第一个replace
的路由,也就是图中的/path1
,表现异常。
具体react-router
版本
部分代码:
import {Router, hashHistory} from 'react-router';
import {syncHistoryWithStore} from 'react-router-redux';
...
const store = configureStore(hashHistory);
const history = syncHistoryWithStore(hashHistory, store);
<Provider store={store}>
<div style={{height:'100%'}}>
<Router history={history} routes={routes} />
</div>
</Provider>
视图中使用(简单构造视图)
import React from 'react';
import ReactDOM from 'react-dom';
export default React.createClass({
orderBack() {
let { history } = this.props;
history.goBack();
},
render() {
return (
<a onClick={ this.orderBack }>返回</a>
);
}
});
希望遇到上述问题的朋友们能够给予帮助,谢谢!