router bug fix

This commit is contained in:
insanity 2017-08-25 15:03:16 +09:00
parent 4fec91aaef
commit 90be19289a
4 changed files with 39 additions and 15 deletions

View File

@ -32,19 +32,19 @@ export class ProbeDetailLayout extends React.Component<Props, State> {
const sub = [ const sub = [
{ {
'name': 'Info', 'name': 'Info',
'path': this.state.currUrl, 'path': '/',
}, },
{ {
'name': 'Host', 'name': 'Host',
'path': this.state.currUrl + '/host', 'path': '/host',
}, },
{ {
'name': 'History', 'name': 'History',
'path': this.state.currUrl + '/history', 'path': '/history',
}, },
{ {
'name': 'Targets', 'name': 'Targets',
'path': this.state.currUrl + '/targets', 'path': '/targets',
}, },
]; ];
return ( return (
@ -52,7 +52,7 @@ export class ProbeDetailLayout extends React.Component<Props, State> {
<LeftMenu /> <LeftMenu />
<Segment basic style={{ margin: '0 0 0 210px', padding: '0' }}> <Segment basic style={{ margin: '0 0 0 210px', padding: '0' }}>
<Header /> <Header />
<TitleBarContainer sub={sub} location={this.props.location.pathname}/> <TitleBarContainer sub={sub} location={this.props.location.pathname} />
<Segment basic> <Segment basic>
<Switch> <Switch>
<Route exact={true} path={`${this.props.match.url}/:id`} component={ProbeDetail} /> <Route exact={true} path={`${this.props.match.url}/:id`} component={ProbeDetail} />
@ -68,5 +68,6 @@ export class ProbeDetailLayout extends React.Component<Props, State> {
} }
} }
export default ProbeDetailLayout; export default ProbeDetailLayout;

View File

@ -30,19 +30,19 @@ class SensorDetailLayout extends React.Component<Props, State> {
const sub = [ const sub = [
{ {
'name': 'Info', 'name': 'Info',
'path': this.state.currUrl, 'path': '/',
}, },
{ {
'name': 'Items', 'name': 'Items',
'path': this.state.currUrl + '/items', 'path': '/items',
}, },
{ {
'name': 'Setup', 'name': 'Setup',
'path': this.state.currUrl + '/setup', 'path': '/setup',
}, },
{ {
'name': 'History', 'name': 'History',
'path': this.state.currUrl + '/history', 'path': '/history',
}, },
]; ];
return ( return (

View File

@ -30,15 +30,15 @@ export class TargetDetailLayout extends React.Component<Props, State> {
const sub = [ const sub = [
{ {
'name': 'Info', 'name': 'Info',
'path': this.state.currUrl + '', 'path': '',
}, },
{ {
'name': 'Sensor', 'name': 'Sensor',
'path': this.state.currUrl + '/sensor', 'path': '/sensor',
}, },
{ {
'name': 'History', 'name': 'History',
'path': this.state.currUrl + '/history', 'path': '/history',
}, },
]; ];
return ( return (

View File

@ -26,12 +26,35 @@ export class TitleBar extends React.Component<Props, State> {
}; };
} }
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 { public handleMenu(menu: any, index: number): any {
this.setState({ this.setState({
selected: index, selected: index,
}); });
if (this.state.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<Props, State> {
elems.push( elems.push(
<Breadcrumb.Section key={index++} onClick={this.handleBreadcrumb.bind(this, path)}> <Breadcrumb.Section key={index++} onClick={this.handleBreadcrumb.bind(this, path)}>
{this.capitalizeFirst(item)} {this.capitalizeFirst(item)}
{/* <Dropdown inline options={options} defaultValue={this.capitalizeFirst(item)}/> */} {/* <Dropdown inline options={options} defaultValue={this.capitalizeFirst(item)}/> */}
</Breadcrumb.Section>); </Breadcrumb.Section>);
elems.push(<Breadcrumb.Divider key={index++} />); elems.push(<Breadcrumb.Divider key={index++} />);
} }
@ -96,7 +119,7 @@ export class TitleBar extends React.Component<Props, State> {
public render(): JSX.Element { public render(): JSX.Element {
return ( return (
<Menu fluid style={{ borderLeft: '0px', borderRight: '0px', boxShadow: 'none', borderRadius: '0', marginTop:'0'}} pointing> <Menu fluid style={{ borderLeft: '0px', borderRight: '0px', boxShadow: 'none', borderRadius: '0', marginTop: '0' }} pointing>
<Menu.Item style={{ width: '250px' }} > <Menu.Item style={{ width: '250px' }} >
<Header as='h3'>{this.showTitle()} <Header as='h3'>{this.showTitle()}
<Header.Subheader> <Header.Subheader>