修改user/org路由时的bug

This commit is contained in:
何童崇 2021-08-30 17:42:13 +08:00
parent 0b64631222
commit 662a758980
4 changed files with 20 additions and 19 deletions

View File

@ -101,6 +101,7 @@ class App extends Component {
occupation: 0,
mygetHelmetapi: null,
pathType: null,
pathName:'',
}
}
@ -109,29 +110,30 @@ class App extends Component {
let pathname = window.location.pathname ? window.location.pathname.split('/')[1] : '';
pathname && this.getPathnameType(pathname);
this.unlisten = this.props.history.listen((location,action) => {
// 最新路由的 location 对象,可以通过比较 pathname 是否相同来判断路由的变化情况
let newPathname = location.pathname.split('/')[1];
newPathname&&this.getPathnameType(newPathname);
// 添加路由监听,决定组织还是个人
this.unlisten = this.props.history.listen((location) => {
let newPathname = location.pathname.split('/')[1];
if(this.state.pathName!==newPathname){
newPathname && this.getPathnameType(newPathname);
}
});
}
getPathnameType = (pathname) => {
let keyWord = ["Gitlink", "Trustie", "explore", "settings", "setting", "CCF", "mulan", "wiki", "issues", "setting", "trending", "code", "projects", "pulls", "mine", "login", "register", "email",];
if (!keyWord.includes('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"];
if (!keyWord.includes(pathname)) {
let url = `/owners/${pathname}.json`;
axios.get(url).then((response) => {
if (response && response.status === 200) {
this.setState({
pathType: response.data.type || '404'
pathType: response.data.type || '404',
pathName:pathname,
})
}
});
}
}
HideAddcoursestypess = (i) => {
this.setState({
Addcoursestype: false,

View File

@ -11,9 +11,9 @@ broadcastChannelOnmessage('refreshPage', () => {
})
function locationurl(list) {
if (window.location.port !== "3007") {
// if (window.location.port !== "3007") {
window.location.href = list
}
// }
}
// TODO 开发期多个身份切换
let debugType = ""
@ -85,7 +85,10 @@ export function initAxiosInterceptors(props) {
}
if (response.data.status === 404) {
locationurl('/nopage');
let responseURL = response.data.request.responseURL;
if (responseURL.indexOf('/api/users/') === -1 && responseURL.indexOf('/api/organizations/') === -1) {
locationurl('/nopage');
}
}
if (response.data.status === 500) {

View File

@ -56,10 +56,6 @@ export default Form.create()(
})
}
function test(){
history.push(`/test2org`);
}
useEffect(()=>{
setFieldsValue({
visibility:"common"
@ -149,7 +145,7 @@ export default Form.create()(
<p className="mt20">
<Button type="primary" className="mr30" onClick={createOrganize}>创建组织</Button>
<Button className="grey" onClick={()=>{window.history.back(-1)}}>取消</Button>
<Button className="grey" onClick={test}>test</Button>
<Button className="grey" onClick={()=>{test}}>test</Button>
</p>
</div>
)

View File

@ -77,7 +77,7 @@ function Detail(props){
{
detail &&
<Cards
src={`/organize/${detail.name}`}
src={`/${detail.name}`}
title={detail.nickname}
desc={!buttonflag && detail.description}
img={detail.avatar_url}