修改路由带来的bug

This commit is contained in:
何童崇 2021-09-02 13:37:24 +08:00
parent 9b62b3b047
commit 559b797c2e
8 changed files with 55 additions and 49 deletions

View File

@ -91,6 +91,10 @@ const ProjectIndex = Loadable({
loader: () => import("./forge/Index"), loader: () => import("./forge/Index"),
loading: Loading, loading: Loading,
}); });
// 此处仅维护前端可能的一级路由,不用进行项目或者组织判断的字段。
const keyWord = ["explore", "settings", "setting", "CCF", "mulan", "wiki", "issues", "setting", "trending", "code", "projects", "pulls", "mine", "login", "register", "email", "export", "nopage", "404", "403", "500", "501", "search"];
class App extends Component { class App extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
@ -101,7 +105,7 @@ class App extends Component {
occupation: 0, occupation: 0,
mygetHelmetapi: null, mygetHelmetapi: null,
pathType: null, pathType: null,
pathName:'', pathName: '',
} }
} }
@ -113,14 +117,15 @@ class App extends Component {
// 添加路由监听,决定组织还是个人 // 添加路由监听,决定组织还是个人
this.unlisten = this.props.history.listen((location) => { this.unlisten = this.props.history.listen((location) => {
let newPathname = location.pathname.split('/')[1]; let newPathname = location.pathname.split('/')[1];
if(this.state.pathName!==newPathname){ if (this.state.pathName !== newPathname) {
this.setState({pathType:''}); this.setState({ pathType: '' });
newPathname && this.getPathnameType(newPathname); newPathname && this.getPathnameType(newPathname);
} }
}); });
} }
shouldComponentUpdate(nextProps, nextState) { shouldComponentUpdate(nextProps, nextState) {
// (!keyWord.includes(this.props.location.pathname.split('/')[1])) &&
if (nextProps.location.pathname.split('/')[1] !== this.props.location.pathname.split('/')[1] && nextState.pathType === this.state.pathType) { if (nextProps.location.pathname.split('/')[1] !== this.props.location.pathname.split('/')[1] && nextState.pathType === this.state.pathType) {
return false; return false;
} else { } else {
@ -129,17 +134,21 @@ class App extends Component {
} }
getPathnameType = (pathname) => { getPathnameType = (pathname) => {
let keyWord = ["Gitlink", "Trustie", "explore", "settings", "setting", "CCF", "mulan", "wiki", "issues", "setting", "trending", "code", "projects", "pulls", "mine", "login", "register", "email", "export", "nopage", "404", "403", "500", "501", "search"];
if (!keyWord.includes(pathname)) { if (!keyWord.includes(pathname)) {
let url = `/owners/${pathname}.json`; let url = `/owners/${pathname}.json`;
axios.get(url).then((response) => { axios.get(url).then((response) => {
if (response && response.status === 200) { if (response && response.status === 200) {
this.setState({ this.setState({
pathType: response.data.type || '404', pathType: response.data.type || '404',
pathName:pathname, pathName: pathname,
}) })
} }
}); });
}else{
this.setState({
pathType: pathname,
pathName: pathname,
});
} }
} }
@ -277,7 +286,7 @@ class App extends Component {
} }
}> }>
</Route> </Route>
<Route <Route
path="/register" path="/register"
render={ render={
@ -308,15 +317,6 @@ class App extends Component {
} }
/> />
{/* <Route
path={"/:owner/:projectsId"}
render={
(props) => {
return (<Projects {...this.props} {...props} {...this.state} />)
}
}>
</Route> */}
{/*项目*/} {/*项目*/}
<Route <Route
path={"/projects"} path={"/projects"}
@ -342,19 +342,21 @@ class App extends Component {
return (<OrganizeIndex {...props} {...this.props} {...this.state} />) return (<OrganizeIndex {...props} {...this.props} {...this.state} />)
} }
}> }>
</Route> : pathType === '404' ? <Route path="/nopage" component={Shixunnopage} /> : <Route exact path="/" </Route> : pathType === '404' ? <Route path="/nopage" component={Shixunnopage} /> :
render={ <Route exact path="/"
(props) => ( render={
personal && personal.length > 0 ? (props) => (
<InfosIndex {...this.props} {...props} /> personal && personal.length > 0 ?
: <InfosIndex {...this.props} {...props} />
<ProjectIndex {...this.props} {...props} /> :
) <ProjectIndex {...this.props} {...props} />
} )
/> }
/>
// <Route path="/" component={Loading} />
} }
{/* 组织 */} {/* 组织 */}
<Route path={"/organize"} <Route path={"/organize"}
render={ render={

View File

@ -70,12 +70,6 @@ class Index extends Component {
<ProjectIndex {...this.props} {...props} /> <ProjectIndex {...this.props} {...props} />
)} )}
></Route> ></Route>
<Route
path="/"
render={(props) => (
<ProjectIndex {...this.props} {...props} />
)}
></Route>
</Switch> </Switch>
</div> </div>
); );

View File

@ -179,11 +179,9 @@ class Setting extends Component {
content: <span style={{display:"block",textAlign:"left"}}>该操作无法撤销且将会一并删除相关的易修合并请求工作流里程碑动态等数据<br/>是否确认删除 <span style={{fontWeight:"bold"}}>{owner}/{projectName}({projectsId})</span></span>, content: <span style={{display:"block",textAlign:"left"}}>该操作无法撤销且将会一并删除相关的易修合并请求工作流里程碑动态等数据<br/>是否确认删除 <span style={{fontWeight:"bold"}}>{owner}/{projectName}({projectsId})</span></span>,
onOk: () => { onOk: () => {
const url = `/${owner}/${projectsId}.json`; const url = `/${owner}/${projectsId}.json`;
axios axios.delete(url).then((result) => {
.delete(url)
.then((result) => {
this.props.showNotification("仓库删除成功!"); this.props.showNotification("仓库删除成功!");
this.props.history.push("/projects"); this.props.history.push(`/${owner}`);
}) })
.catch((error) => { .catch((error) => {
console.log(error); console.log(error);

View File

@ -87,9 +87,9 @@ export default ((props) => {
if (username) { if (username) {
const url = `/organizations/${OIdentifier}/teams/${groupId}/team_users/quit.json`; const url = `/organizations/${OIdentifier}/teams/${groupId}/team_users/quit.json`;
axios.delete(url).then((result) => { axios.delete(url).then((result) => {
if (result && result.data) { if (result && result.message==='success') {
props.showNotification(`已成功退出团队!`); props.showNotification(`已成功退出团队!`);
props.history.push(`/${OIdentifier}`); props.history.push(`/${username}`);
} }
}).catch((error) => { }); }).catch((error) => { });
} }

View File

@ -72,6 +72,14 @@ export default withRouter(CNotificationHOC()(SnackbarHOC()(TPMIndexHOC(
}} }}
></Route> ></Route>
{/* 组织详情(包含组织设置) */}
<Route
path="/:OIdentifier/setting"
render={(p) => (
<DetailIndex {...props} {...p}/>
)}
></Route>
{/* 组织下的项目详情 */} {/* 组织下的项目详情 */}
<Route <Route
path="/:owner/:projectsId" path="/:owner/:projectsId"

View File

@ -61,8 +61,8 @@ function List(props){
) )
const menu_new=( const menu_new=(
<Menu> <Menu>
<Menu.Item key="updated_on"><Link to={`/deposit/new/${OIdentifier}`}>新建托管项目</Link></Menu.Item> <Menu.Item key="updated_on"><Link to={`/projects/deposit/new/${OIdentifier}`}>新建托管项目</Link></Menu.Item>
<Menu.Item key="created_on"><Link to={`/mirror/new/${OIdentifier}`}>新建镜像项目</Link></Menu.Item> <Menu.Item key="created_on"><Link to={`/projects/mirror/new/${OIdentifier}`}>新建镜像项目</Link></Menu.Item>
</Menu> </Menu>
) )

View File

@ -145,7 +145,6 @@ export default Form.create()(
<p className="mt20"> <p className="mt20">
<Button type="primary" className="mr30" onClick={createOrganize}>创建组织</Button> <Button type="primary" className="mr30" onClick={createOrganize}>创建组织</Button>
<Button className="grey" onClick={()=>{window.history.back(-1)}}>取消</Button> <Button className="grey" onClick={()=>{window.history.back(-1)}}>取消</Button>
<Button className="grey" onClick={()=>{test}}>test</Button>
</p> </p>
</div> </div>
) )

View File

@ -22,21 +22,26 @@ const ProjectDetail = Loadable({
}); });
export default withRouter( export default withRouter(
(CNotificationHOC()(SnackbarHOC()(TPMIndexHOC((props) => { (CNotificationHOC()(SnackbarHOC()(TPMIndexHOC((props) => {
// //
let secondRouter = ''; let secondRouter = '';
let firstRouter = '';
if (props.location.pathname) { if (props.location.pathname) {
firstRouter =props.location.pathname.split('/')[1];
secondRouter = props.location.pathname.split('/')[2]; secondRouter = props.location.pathname.split('/')[2];
} }
// explore
let changePathProps={...props};
if(firstRouter==='explore'){
let login=props.current_user.login;
changePathProps.match.path=`/${login}`;
changePathProps.match.url=`/${login}`;
changePathProps.location.pathname=`/${login}`;
changePathProps.history.location.pathname=`/${login}`;
}
let userRouterArr = ['statistics', 'projects', 'notice', 'devops', 'organizes', 'info', 'watchers', 'fan_users', 'password']; let userRouterArr = ['statistics', 'projects', 'notice', 'devops', 'organizes', 'info', 'watchers', 'fan_users', 'password'];
return ( return (
<Switch> <Switch>
{/* <Route
path="/:username"
render={(p) => (
secondRouter && (!userRouterArr.includes(secondRouter)) ?
<ProjectDetail {...props} {...p} /> : <Infos {...props} {...p} />
)}
></Route> */}
{secondRouter && (!userRouterArr.includes(secondRouter)) ? <Route {secondRouter && (!userRouterArr.includes(secondRouter)) ? <Route
path="/:owner/:projectsId" path="/:owner/:projectsId"
@ -46,7 +51,7 @@ export default withRouter(
></Route> : <Route ></Route> : <Route
path="/:username" path="/:username"
render={(p) => ( render={(p) => (
<Infos {...props} {...p} /> <Infos {...changePathProps} {...p} />
)} )}
></Route>} ></Route>}