mirror of
https://github.com/YMFE/yapi.git
synced 2024-12-09 05:00:30 +08:00
fix: 优化分组页的路由
This commit is contained in:
parent
66b23b2440
commit
edd82fd3a8
@ -45,7 +45,7 @@ export default class App extends Component {
|
||||
<div className="router-main">
|
||||
<Header />
|
||||
<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="/user" component={requireAuthentication(User)} />
|
||||
<Route path="/News" component={requireAuthentication(News)} />
|
||||
|
@ -4,7 +4,7 @@ import { connect } from 'react-redux'
|
||||
import { Button, Icon, Modal, Input, message, Menu, Row, Col } from 'antd'
|
||||
import { autobind } from 'core-decorators';
|
||||
import axios from 'axios';
|
||||
|
||||
import { withRouter } from 'react-router';
|
||||
const { TextArea } = Input;
|
||||
const Search = Input.Search;
|
||||
const confirm = Modal.confirm;
|
||||
@ -29,6 +29,7 @@ import './GroupList.scss'
|
||||
setGroupList
|
||||
}
|
||||
)
|
||||
@withRouter
|
||||
export default class GroupList extends Component {
|
||||
|
||||
static propTypes = {
|
||||
@ -36,7 +37,9 @@ export default class GroupList extends Component {
|
||||
currGroup: PropTypes.object,
|
||||
fetchGroupList: PropTypes.func,
|
||||
setCurrGroup: PropTypes.func,
|
||||
setGroupList: PropTypes.func
|
||||
setGroupList: PropTypes.func,
|
||||
match: PropTypes.object,
|
||||
history: PropTypes.object
|
||||
}
|
||||
|
||||
state = {
|
||||
@ -54,8 +57,19 @@ export default class GroupList extends Component {
|
||||
}
|
||||
|
||||
componentWillMount() {
|
||||
const groupName = this.props.match.params.groupName;
|
||||
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.props.setCurrGroup(currGroup)
|
||||
});
|
||||
@ -142,6 +156,7 @@ export default class GroupList extends Component {
|
||||
const groupId = e.key;
|
||||
const currGroup = this.props.groupList.find((group) => { return +group._id === +groupId });
|
||||
this.props.setCurrGroup(currGroup);
|
||||
this.props.history.push(`${currGroup.group_name}`);
|
||||
}
|
||||
|
||||
@autobind
|
||||
|
@ -9,7 +9,7 @@ export default () => {
|
||||
<div className="router-main">
|
||||
<Header/>
|
||||
<Route path="/" component={ Home } exact />
|
||||
<Route path="/ProjectGroups" component={ ProjectGroups } />
|
||||
<Route path="/group/:groupName" component={ ProjectGroups } />
|
||||
<Route path="/Interface" component={ Interface } />
|
||||
<Route path="/user" component={User} />
|
||||
<Route path="/News" component={ News } />
|
||||
|
Loading…
Reference in New Issue
Block a user