route history back bug fix

This commit is contained in:
insanity 2017-08-28 18:49:47 +09:00
parent 4db19042c5
commit e3e1b8f411
5 changed files with 26 additions and 13 deletions

View File

@ -15,7 +15,6 @@ import HistoryView from '../../views/history/List';
export interface Props extends RouteComponentProps<any> {
}
export interface State {
currUrl: string;
}
export class ProbeDetailLayout extends React.Component<Props, State> {
@ -23,7 +22,6 @@ export class ProbeDetailLayout extends React.Component<Props, State> {
constructor(props: Props, context: State) {
super(props, context);
this.state = {
currUrl: this.props.location.pathname,
};
}
@ -52,7 +50,7 @@ export class ProbeDetailLayout extends React.Component<Props, State> {
<LeftMenu />
<Segment basic style={{ margin: '0 0 0 210px', padding: '0' }}>
<Header />
<TitleBarContainer sub={sub} location={this.props.location.pathname} />
<TitleBarContainer sub={sub} location={this.props.location.pathname} history={this.props.history}/>
<Segment basic>
<Switch>
<Route exact={true} path={`${this.props.match.url}/:id`} component={ProbeDetail} />

View File

@ -14,7 +14,6 @@ import HistoryView from '../../views/history/List';
export interface Props extends RouteComponentProps<any> {
}
export interface State {
currUrl: string;
}
class SensorDetailLayout extends React.Component<Props, State> {
@ -22,7 +21,6 @@ class SensorDetailLayout extends React.Component<Props, State> {
public constructor(props?: Props, context?: State) {
super(props, context);
this.state = {
currUrl: this.props.location.pathname,
};
}
@ -50,7 +48,7 @@ class SensorDetailLayout extends React.Component<Props, State> {
<LeftMenu />
<Segment basic style={{ margin: '0 0 0 210px', padding: '0' }}>
<Header />
<TitleBarContainer sub={sub} location={this.props.location.pathname} />
<TitleBarContainer sub={sub} location={this.props.location.pathname} history={this.props.history}/>
{/*<TitleBar title='Sensor Details' sub={sub} />*/}
<Segment basic>
<Switch>

View File

@ -13,7 +13,6 @@ import HistoryView from '../../views/history/List';
export interface Props extends RouteComponentProps<any> {
}
export interface State {
currUrl: string;
}
export class TargetDetailLayout extends React.Component<Props, State> {
@ -21,7 +20,6 @@ export class TargetDetailLayout extends React.Component<Props, State> {
constructor(props: Props, context: State) {
super(props, context);
this.state = {
currUrl: this.props.location.pathname,
};
}
@ -30,7 +28,7 @@ export class TargetDetailLayout extends React.Component<Props, State> {
const sub = [
{
'name': 'Info',
'path': '',
'path': '/',
},
{
'name': 'Sensor',
@ -46,7 +44,7 @@ export class TargetDetailLayout extends React.Component<Props, State> {
<LeftMenu />
<Segment basic style={{ margin: '0 0 0 210px', padding: '0' }}>
<Header />
<TitleBarContainer title='Target Details' sub={sub} location={this.props.location.pathname} />
<TitleBarContainer sub={sub} location={this.props.location.pathname} history={this.props.history}/>
<Segment basic>
<Switch>
<Route exact={true} path={`${this.props.match.url}/:id`} component={TargetDetail} />

View File

@ -5,6 +5,7 @@ import { Grid, Container, Breadcrumb, Header, Menu, Input, Segment, Dropdown } f
export interface StateProps {
sub: any;
location: string;
history: any;
}
export interface DispatchProps {
@ -32,13 +33,30 @@ export class TitleBar extends React.Component<Props, State> {
}
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});
for (let i = 0; i < this.props.sub.length; i++) {
if (this.props.sub[i].name.toLowerCase() === last) {
this.setState({ selected: i });
return;
}
}
}
public componentWillUpdate(nextProps: Props, nextState: State): void {
if (nextProps !== this.props) {
if (!this.props.history.location.pathname) {
return;
}
let last = this.props.history.location.pathname.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 });
return;
}
}
this.setState({ selected: 0 });
}
}
public handleMenu(menu: any, index: number): any {
this.setState({
selected: index,

View File

@ -11,6 +11,7 @@ export function mapStateToProps(state: any, ownProps: any): StateProps {
return {
sub: ownProps.sub,
location: ownProps.location,
history: ownProps.history,
};
}