From 90be19289a12292bd14624ebde5b29ba33fa013e Mon Sep 17 00:00:00 2001 From: insanity Date: Fri, 25 Aug 2017 15:03:16 +0900 Subject: [PATCH] router bug fix --- .../app/views/layout/ProbeDetailLayout.tsx | 11 +++---- .../app/views/layout/SensorDetailLayout.tsx | 8 ++--- .../app/views/layout/TargetDetailLayout.tsx | 6 ++-- .../@overflow/app/views/layout/TitleBar.tsx | 29 +++++++++++++++++-- 4 files changed, 39 insertions(+), 15 deletions(-) diff --git a/src/ts/@overflow/app/views/layout/ProbeDetailLayout.tsx b/src/ts/@overflow/app/views/layout/ProbeDetailLayout.tsx index c5a87bd..056830b 100644 --- a/src/ts/@overflow/app/views/layout/ProbeDetailLayout.tsx +++ b/src/ts/@overflow/app/views/layout/ProbeDetailLayout.tsx @@ -32,19 +32,19 @@ export class ProbeDetailLayout extends React.Component { const sub = [ { 'name': 'Info', - 'path': this.state.currUrl, + 'path': '/', }, { 'name': 'Host', - 'path': this.state.currUrl + '/host', + 'path': '/host', }, { 'name': 'History', - 'path': this.state.currUrl + '/history', + 'path': '/history', }, { 'name': 'Targets', - 'path': this.state.currUrl + '/targets', + 'path': '/targets', }, ]; return ( @@ -52,7 +52,7 @@ export class ProbeDetailLayout extends React.Component {
- + @@ -68,5 +68,6 @@ export class ProbeDetailLayout extends React.Component { } } + export default ProbeDetailLayout; diff --git a/src/ts/@overflow/app/views/layout/SensorDetailLayout.tsx b/src/ts/@overflow/app/views/layout/SensorDetailLayout.tsx index 157efa9..5bbfe56 100644 --- a/src/ts/@overflow/app/views/layout/SensorDetailLayout.tsx +++ b/src/ts/@overflow/app/views/layout/SensorDetailLayout.tsx @@ -30,19 +30,19 @@ class SensorDetailLayout extends React.Component { const sub = [ { 'name': 'Info', - 'path': this.state.currUrl, + 'path': '/', }, { 'name': 'Items', - 'path': this.state.currUrl + '/items', + 'path': '/items', }, { 'name': 'Setup', - 'path': this.state.currUrl + '/setup', + 'path': '/setup', }, { 'name': 'History', - 'path': this.state.currUrl + '/history', + 'path': '/history', }, ]; return ( diff --git a/src/ts/@overflow/app/views/layout/TargetDetailLayout.tsx b/src/ts/@overflow/app/views/layout/TargetDetailLayout.tsx index 4a13a90..57717eb 100644 --- a/src/ts/@overflow/app/views/layout/TargetDetailLayout.tsx +++ b/src/ts/@overflow/app/views/layout/TargetDetailLayout.tsx @@ -30,15 +30,15 @@ export class TargetDetailLayout extends React.Component { const sub = [ { 'name': 'Info', - 'path': this.state.currUrl + '', + 'path': '', }, { 'name': 'Sensor', - 'path': this.state.currUrl + '/sensor', + 'path': '/sensor', }, { 'name': 'History', - 'path': this.state.currUrl + '/history', + 'path': '/history', }, ]; return ( diff --git a/src/ts/@overflow/app/views/layout/TitleBar.tsx b/src/ts/@overflow/app/views/layout/TitleBar.tsx index ff67dda..7c5c4cd 100644 --- a/src/ts/@overflow/app/views/layout/TitleBar.tsx +++ b/src/ts/@overflow/app/views/layout/TitleBar.tsx @@ -26,12 +26,35 @@ export class TitleBar extends React.Component { }; } + public componentWillMount(): void { + if (this.props.sub === undefined || this.props.sub === null) { + return; + } + + let last = this.props.location.split('/').pop().toLowerCase(); + for(let i = 0; i < this.props.sub.length; i++) { + if(this.props.sub[i].name.toLowerCase() === last) { + this.setState({selected: i}); + } + } + } + public handleMenu(menu: any, index: number): any { this.setState({ selected: index, }); if (this.state.selected !== index) { - this.props.onRedirect(menu.path); + let id = null; + let urlArr = this.props.location.split('/'); + for (let u of urlArr) { + let reg = /^(?:[1-9]\d*|\d)$/; + if (reg.test(u)) { + id = u; + } + } + let url = '/' + urlArr[1] + '/' + id + menu.path; + + this.props.onRedirect(url); } } @@ -86,7 +109,7 @@ export class TitleBar extends React.Component { elems.push( {this.capitalizeFirst(item)} - {/* */} + {/* */} ); elems.push(); } @@ -96,7 +119,7 @@ export class TitleBar extends React.Component { public render(): JSX.Element { return ( - +
{this.showTitle()}