fix: 优化分组页的路由

This commit is contained in:
qitmac000249 2017-07-25 13:17:54 +08:00
parent 237a53ded6
commit af6680b589
3 changed files with 20 additions and 5 deletions

View File

@ -45,7 +45,7 @@ export default class App extends Component {
<div className="router-main"> <div className="router-main">
<Header /> <Header />
<Route path="/" component={Home} exact /> <Route path="/" component={Home} exact />
<Route path="/ProjectGroups" component={requireAuthentication(ProjectGroups)} /> <Route path="/group/:groupName" component={requireAuthentication(ProjectGroups)} />
<Route path="/Interface" component={requireAuthentication(Interface)} /> <Route path="/Interface" component={requireAuthentication(Interface)} />
<Route path="/user" component={requireAuthentication(User)} /> <Route path="/user" component={requireAuthentication(User)} />
<Route path="/News" component={requireAuthentication(News)} /> <Route path="/News" component={requireAuthentication(News)} />

View File

@ -4,7 +4,7 @@ import { connect } from 'react-redux'
import { Button, Icon, Modal, Input, message, Menu, Row, Col } from 'antd' import { Button, Icon, Modal, Input, message, Menu, Row, Col } from 'antd'
import { autobind } from 'core-decorators'; import { autobind } from 'core-decorators';
import axios from 'axios'; import axios from 'axios';
import { withRouter } from 'react-router';
const { TextArea } = Input; const { TextArea } = Input;
const Search = Input.Search; const Search = Input.Search;
const confirm = Modal.confirm; const confirm = Modal.confirm;
@ -29,6 +29,7 @@ import './GroupList.scss'
setGroupList setGroupList
} }
) )
@withRouter
export default class GroupList extends Component { export default class GroupList extends Component {
static propTypes = { static propTypes = {
@ -36,7 +37,9 @@ export default class GroupList extends Component {
currGroup: PropTypes.object, currGroup: PropTypes.object,
fetchGroupList: PropTypes.func, fetchGroupList: PropTypes.func,
setCurrGroup: PropTypes.func, setCurrGroup: PropTypes.func,
setGroupList: PropTypes.func setGroupList: PropTypes.func,
match: PropTypes.object,
history: PropTypes.object
} }
state = { state = {
@ -54,8 +57,19 @@ export default class GroupList extends Component {
} }
componentWillMount() { componentWillMount() {
const groupName = this.props.match.params.groupName;
this.props.fetchGroupList().then(() => { this.props.fetchGroupList().then(() => {
const currGroup = this.props.groupList[0] || { group_name: '', group_desc: '' }; let currGroup = this.props.groupList[0] || { group_name: '', group_desc: '' };
if(this.props.groupList.length && groupName){
for(let i = 0;i<this.props.groupList.length;i++){
if(this.props.groupList[i].group_name === groupName){
currGroup = this.props.groupList[i];
}else{
this.props.history.push(`${currGroup.group_name}`);
}
}
}
console.log(currGroup);
this.setState({groupList: this.props.groupList}); this.setState({groupList: this.props.groupList});
this.props.setCurrGroup(currGroup) this.props.setCurrGroup(currGroup)
}); });
@ -142,6 +156,7 @@ export default class GroupList extends Component {
const groupId = e.key; const groupId = e.key;
const currGroup = this.props.groupList.find((group) => { return +group._id === +groupId }); const currGroup = this.props.groupList.find((group) => { return +group._id === +groupId });
this.props.setCurrGroup(currGroup); this.props.setCurrGroup(currGroup);
this.props.history.push(`${currGroup.group_name}`);
} }
@autobind @autobind

View File

@ -9,7 +9,7 @@ export default () => {
<div className="router-main"> <div className="router-main">
<Header/> <Header/>
<Route path="/" component={ Home } exact /> <Route path="/" component={ Home } exact />
<Route path="/ProjectGroups" component={ ProjectGroups } /> <Route path="/group/:groupName" component={ ProjectGroups } />
<Route path="/Interface" component={ Interface } /> <Route path="/Interface" component={ Interface } />
<Route path="/user" component={User} /> <Route path="/user" component={User} />
<Route path="/News" component={ News } /> <Route path="/News" component={ News } />