主要是根据hash来进行判断,/detail表示没数据。/detail/:id表示有数据,这样的hashchange要在哪里进行判断和修改state。不太明白咋弄。求大神帮忙。
你的路由要配置好,保证这两个url都能访问到同一个组件。
组件代码
imort React from 'react';
export default class Component extends React.Component{
constructor(...props){
super(...props);
this.state = {
list:[]
};
}
componentDidMount(){
if(this.props.params.id){
//有数据的处理
}else{
//无数据的处理
}
}
}
Component.contextTypes = {
router:React.PropTypes.object.isRequired
};