diff --git a/src/modules/tpm/NewHeader.js b/src/modules/tpm/NewHeader.js index 2ead4e4f..e2c47bb3 100644 --- a/src/modules/tpm/NewHeader.js +++ b/src/modules/tpm/NewHeader.js @@ -50,7 +50,8 @@ class NewHeader extends Component { } } componentDidMount() { - this.getAppdata(); + // this.getAppdata(); + this.geturlsdata(); window._header_componentHandler = this; //下拉框的显示隐藏 @@ -547,23 +548,19 @@ class NewHeader extends Component { geturlsdata = () => { let url = "/setting.json"; axios.get(url).then((response) => { - if (response) { - if (response.data) { - this.setState({ - mygetHelmetapi2: response.data.setting - }); - localStorage.setItem('chromesetting', JSON.stringify(response.data.setting)); - localStorage.setItem('chromesettingresponse', JSON.stringify(response)); - try { - if (response.data.setting.tab_logo_url) { - this.gettablogourldata(response); - } else { - this.gettablogourlnull(); - } - } catch (e) { + if (response && response.data) { + this.setState({ + mygetHelmetapi2: response.data.setting + }); + // localStorage.setItem('chromesetting', JSON.stringify(response.data.setting)); + // localStorage.setItem('chromesettingresponse', JSON.stringify(response)); + try { + if (response.data.setting.tab_logo_url) { + this.gettablogourldata(response); + } else { this.gettablogourlnull(); } - } else { + } catch (e) { this.gettablogourlnull(); } } else { @@ -571,29 +568,30 @@ class NewHeader extends Component { } }).catch((error) => { this.gettablogourlnull(); - }); } matchpaths = (url) => { const { match } = this.props; - if (url === '/forums' && match.path === '/forums') { - return true - } else if (url.startsWith('/projects') && match.path.startsWith('/projects')) { - return true - } else if (url.startsWith('/paths') && match.path.startsWith('/paths')) { - return true - } else if (url.startsWith('/courses') && match.path.startsWith('/courses')) { - return true - } else if (url.startsWith('/competitions') && match.path.startsWith('/competitions')) { - return true - } else if (url.startsWith('/statistics') && match.path.startsWith('/statistics')) { - return true - } else if (url.startsWith('/users') && match.path.startsWith('/users')) { - return true - } else { - return false + if(url){ + if (url === '/forums' && match.path === '/forums') { + return true + } else if (url.startsWith('/projects') && match.path.startsWith('/projects')) { + return true + } else if (url.startsWith('/paths') && match.path.startsWith('/paths')) { + return true + } else if (url.startsWith('/courses') && match.path.startsWith('/courses')) { + return true + } else if (url.startsWith('/competitions') && match.path.startsWith('/competitions')) { + return true + } else if (url.startsWith('/statistics') && match.path.startsWith('/statistics')) { + return true + } else if (url.startsWith('/users') && match.path.startsWith('/users')) { + return true + } else { + return false + } } } @@ -741,7 +739,7 @@ class NewHeader extends Component { var new_link = item.link; var user_login = this.props.user && this.props.user.login; var is_hidden = item.hidden - if (new_link.indexOf("courses") > -1 || new_link.indexOf("contests") > -1) { + if (new_link && (new_link.indexOf("courses") > -1 || new_link.indexOf("contests") > -1)) { if (user_login) { if (new_link.indexOf("courses") > -1) { new_link = new_link.replace(/courses/g, "users/" + user_login + "/courses") @@ -752,7 +750,7 @@ class NewHeader extends Component { is_hidden = true } } - if (user_login && new_link.indexOf("homes") > -1) { + if (user_login && (new_link && new_link.indexOf("homes") > -1)) { new_link = new_link.replace(/homes/g, "users/" + user_login + "/user_activities") } return (