Minor improvements to onNewRoute (#2328)

- Call onNewRoute when page changed with same component in DiscussionPage and UserPage

- Make app.previous and app.current changed in onNewRoute, not in oninit. This way, when the route is changed, but still handled by the same component, a new PageState object will still be created.
This commit is contained in:
Alexander Skvortsov 2020-10-02 17:10:38 -04:00 committed by GitHub
parent 0b3fe10516
commit 44a96a82ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 4 deletions

View File

@ -10,9 +10,6 @@ export default class Page extends Component {
oninit(vnode) {
super.oninit(vnode);
app.previous = app.current;
app.current = new PageState(this.constructor);
this.onNewRoute();
app.drawer.hide();
@ -33,7 +30,8 @@ export default class Page extends Component {
* adjust the current route name.
*/
onNewRoute() {
app.current.set('routeName', this.attrs.routeName);
app.previous = app.current;
app.current = new PageState(this.constructor, { routeName: this.attrs.routeName });
}
oncreate(vnode) {

View File

@ -99,6 +99,7 @@ export default class DiscussionPage extends Page {
super.onbeforeupdate(vnode);
if (m.route.get() !== this.prevRoute) {
this.onNewRoute();
this.prevRoute = m.route.get();
// If we have routed to the same discussion as we were viewing previously,

View File

@ -34,6 +34,8 @@ export default class UserPage extends Page {
onbeforeupdate() {
const currUsername = m.route.param('username');
if (currUsername !== this.prevUsername) {
this.onNewRoute();
this.prevUsername = currUsername;
this.loadUser(currUsername);