From 485b8d6821579b84c24fada62c5c98765d3e47e1 Mon Sep 17 00:00:00 2001 From: suxiaoxin Date: Thu, 17 Aug 2017 18:00:02 +0800 Subject: [PATCH] fix: fix route some bug --- client/containers/Project/Interface/Interface.js | 7 +++++-- .../Interface/InterfaceList/InterfaceContent.js | 16 ++++++++++------ .../Interface/InterfaceList/InterfaceMenu.js | 10 +++++----- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/client/containers/Project/Interface/Interface.js b/client/containers/Project/Interface/Interface.js index b846aee5..fbb0eb9f 100644 --- a/client/containers/Project/Interface/Interface.js +++ b/client/containers/Project/Interface/Interface.js @@ -1,7 +1,7 @@ import React, { Component } from 'react' import PropTypes from 'prop-types' import { Row, Col, Tabs } from 'antd'; -import { Route } from 'react-router-dom'; +import { Route, Switch, Redirect } from 'react-router-dom'; import './interface.scss' @@ -75,7 +75,10 @@ class Interface extends Component {
- + + + +
diff --git a/client/containers/Project/Interface/InterfaceList/InterfaceContent.js b/client/containers/Project/Interface/InterfaceList/InterfaceContent.js index b4d57a1e..6987f261 100644 --- a/client/containers/Project/Interface/InterfaceList/InterfaceContent.js +++ b/client/containers/Project/Interface/InterfaceList/InterfaceContent.js @@ -27,7 +27,8 @@ class Content extends Component { match: PropTypes.object, list: PropTypes.array, curdata: PropTypes.object, - fetchInterfaceData: PropTypes.func + fetchInterfaceData: PropTypes.func, + history: PropTypes.object } constructor(props) { super(props) @@ -41,17 +42,20 @@ class Content extends Component { this.handleRequest(this.props) } - componentWillReceiveProps(nextProps){ + componentWillReceiveProps(nextProps) { this.handleRequest(nextProps) } - handleRequest(nextProps){ + handleRequest(nextProps) { let matchParams = nextProps.match.params; let _actionId; _actionId = matchParams.actionId; _actionId = parseInt(matchParams.actionId, 10); - if(!nextProps.curdata)return; - if(this._actionId !== _actionId){ + if (_actionId == 0 && nextProps.list.length > 0) { + return this.props.history.replace('/project/' + matchParams.id + '/interface/api/' + nextProps.list[0]._id) + } + if (!nextProps.curdata) return; + if (this._actionId !== _actionId) { this._actionId = _actionId; this.props.fetchInterfaceData(_actionId) } @@ -60,7 +64,7 @@ class Content extends Component { }) } - onChange = (key)=>{ + onChange = (key) => { this.setState({ curtab: key }) diff --git a/client/containers/Project/Interface/InterfaceList/InterfaceMenu.js b/client/containers/Project/Interface/InterfaceList/InterfaceMenu.js index f8e45ca3..8dbd5795 100644 --- a/client/containers/Project/Interface/InterfaceList/InterfaceMenu.js +++ b/client/containers/Project/Interface/InterfaceList/InterfaceMenu.js @@ -62,11 +62,11 @@ class InterfaceMenu extends Component { } async handleRequest() { - let result = await this.props.fetchInterfaceList(this.props.projectId); - let params = this.props.match.params; - if(!params.actionId){ - this.props.history.replace('/project/'+params.id + '/interface/api/' + result.payload.data[0]._id) - } + await this.props.fetchInterfaceList(this.props.projectId); + + // if(!params.actionId){ + // this.props.history.replace('/project/'+params.id + '/interface/api/' + result.payload.data[0]._id) + // } } componentWillMount() {