From 554c72c6db68c71e983cf104dcd5508503570ae1 Mon Sep 17 00:00:00 2001 From: Alexander Skvortsov Date: Thu, 27 Aug 2020 12:31:23 -0400 Subject: [PATCH] IndexPage: change routeName on app.current --- js/src/common/components/Page.js | 14 +++++++++++++- js/src/forum/components/IndexPage.js | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/js/src/common/components/Page.js b/js/src/common/components/Page.js index 16db7624f..917aad5af 100644 --- a/js/src/common/components/Page.js +++ b/js/src/common/components/Page.js @@ -11,7 +11,9 @@ export default class Page extends Component { super.oninit(vnode); app.previous = app.current; - app.current = new PageState(this.constructor, { routeName: vnode.attrs.routeName }); + app.current = new PageState(this.constructor); + + this.onNewRoute(); app.drawer.hide(); app.modal.close(); @@ -24,6 +26,16 @@ export default class Page extends Component { this.bodyClass = ''; } + /** + * A collections of actions to run when the route changes. + * This is extracted here, and not hardcoded in oninit, as oninit is not called + * when a different route is handled by the same component, but we still need to + * adjust the current route name. + */ + onNewRoute() { + app.current.set('routeName', this.attrs.routeName); + } + oncreate(vnode) { super.oncreate(vnode); diff --git a/js/src/forum/components/IndexPage.js b/js/src/forum/components/IndexPage.js index 6c320bcaa..433f5196f 100644 --- a/js/src/forum/components/IndexPage.js +++ b/js/src/forum/components/IndexPage.js @@ -52,6 +52,7 @@ export default class IndexPage extends Page { app.discussions.refreshParams(app.search.params()); + this.onNewRoute(); this.currentPath = curPath; this.setTitle();