mirror of
https://github.com/flarum/core.git
synced 2025-07-16 14:26:25 +02:00
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:
committed by
GitHub
parent
0b3fe10516
commit
44a96a82ef
js/src
@ -10,9 +10,6 @@ export default class Page extends Component {
|
|||||||
oninit(vnode) {
|
oninit(vnode) {
|
||||||
super.oninit(vnode);
|
super.oninit(vnode);
|
||||||
|
|
||||||
app.previous = app.current;
|
|
||||||
app.current = new PageState(this.constructor);
|
|
||||||
|
|
||||||
this.onNewRoute();
|
this.onNewRoute();
|
||||||
|
|
||||||
app.drawer.hide();
|
app.drawer.hide();
|
||||||
@ -33,7 +30,8 @@ export default class Page extends Component {
|
|||||||
* adjust the current route name.
|
* adjust the current route name.
|
||||||
*/
|
*/
|
||||||
onNewRoute() {
|
onNewRoute() {
|
||||||
app.current.set('routeName', this.attrs.routeName);
|
app.previous = app.current;
|
||||||
|
app.current = new PageState(this.constructor, { routeName: this.attrs.routeName });
|
||||||
}
|
}
|
||||||
|
|
||||||
oncreate(vnode) {
|
oncreate(vnode) {
|
||||||
|
@ -99,6 +99,7 @@ export default class DiscussionPage extends Page {
|
|||||||
super.onbeforeupdate(vnode);
|
super.onbeforeupdate(vnode);
|
||||||
|
|
||||||
if (m.route.get() !== this.prevRoute) {
|
if (m.route.get() !== this.prevRoute) {
|
||||||
|
this.onNewRoute();
|
||||||
this.prevRoute = m.route.get();
|
this.prevRoute = m.route.get();
|
||||||
|
|
||||||
// If we have routed to the same discussion as we were viewing previously,
|
// If we have routed to the same discussion as we were viewing previously,
|
||||||
|
@ -34,6 +34,8 @@ export default class UserPage extends Page {
|
|||||||
onbeforeupdate() {
|
onbeforeupdate() {
|
||||||
const currUsername = m.route.param('username');
|
const currUsername = m.route.param('username');
|
||||||
if (currUsername !== this.prevUsername) {
|
if (currUsername !== this.prevUsername) {
|
||||||
|
this.onNewRoute();
|
||||||
|
|
||||||
this.prevUsername = currUsername;
|
this.prevUsername = currUsername;
|
||||||
|
|
||||||
this.loadUser(currUsername);
|
this.loadUser(currUsername);
|
||||||
|
Reference in New Issue
Block a user