import { Route, IndexRoute, Router, hashHistory, browserHistory } from 'react-router'; <Router routes={routes} history={browserHistory}/>
{ comment: { comments:[], leng:0 } detail: { content: "xxx" } home: { loading: false, pos: 0, stories: [] } }
//在home裏面跳轉是觸發fetchDetailData <Link to={ '/detail/'+item.id} onClick={this.props.fetchDetailData.bind(this,item.id) }>
獲取完詳情數據後,這樣store數據就成如下結構 react
{ comment: { comments:[] leng:0 } detail: { content:"xxx" } home: { loading:false pos:29228 stories:Array(201) } }
//在詳情頁detail裏面跳轉是觸發fetchCommentData <Link to={ '/comment/'+this.articleId} onClick={this.props.fetchCommentData.bind(this, this.articleId) }>評論</Link>
獲取完評論數據後,這樣store數據就成如下結構 webpack
{ comment: { comments:Array(20) leng:20 } detail: { content:"xxx" } home: { loading:false pos:29228 stories:Array(201) } }
github地址:https://github.com/fengnovo/webpack-react/tree/master/simpleFetch
//在返回主頁home時,在主頁作判斷,回到最初的最初點擊跳轉時的位置 componentDidMount () { if(this.props.stories.length === 0 ){ this.props.fetchHomeData(this.s) }else{ console.log(this.props.route.component.displayName) if(this.props.route.component.displayName == "Connect(Home)"){ window.scrollTo(0,this.props.pos); } this.s() } }
順便介紹一個好東西,MacDown,麥當勞,一款專門給mac用寫markdown的軟件工具,開源免費又好用
地址:http://macdown.uranusjr.com/git