diff --git a/frontend/src/app.js b/frontend/src/app.js index eafab695d8..300f620264 100644 --- a/frontend/src/app.js +++ b/frontend/src/app.js @@ -54,6 +54,14 @@ class App extends Component { pathPrefix: [], }; this.dirViewPanels = ['my-libs', 'shared-libs', 'org']; // and group + window.onpopstate = this.onpopstate; + } + + onpopstate = (event) => { + if (event.state && event.state.currentTab && event.state.pathPrefix) { + let { currentTab, pathPrefix } = event.state; + this.setState({currentTab, pathPrefix}); + } } componentDidMount() { @@ -129,6 +137,9 @@ class App extends Component { this.setState({ currentTab: tabName, pathPrefix: pathPrefix + }, () => { + let { currentTab, pathPrefix } = this.state; + window.history.replaceState({currentTab: currentTab, pathPrefix: pathPrefix}, null); }); } diff --git a/frontend/src/pages/lib-content-view/lib-content-view.js b/frontend/src/pages/lib-content-view/lib-content-view.js index 44b29754f0..7ed70b32ab 100644 --- a/frontend/src/pages/lib-content-view/lib-content-view.js +++ b/frontend/src/pages/lib-content-view/lib-content-view.js @@ -73,6 +73,7 @@ class LibContentView extends React.Component { updateDetail: false, }; + this.oldonpopstate = window.onpopstate; window.onpopstate = this.onpopstate; this.lastModifyTime = new Date(); this.isNeedUpdateHistoryState = true; // Load, refresh page, switch mode for the first time, no need to set historyState @@ -146,6 +147,7 @@ class LibContentView extends React.Component { } componentWillUnmount() { + window.onpopstate = this.oldonpopstate; collabServer.unwatchRepo(this.props.repoID, this.onRepoUpdateEvent); }