client/routing: fix certain history bug
The bug could be reproduced as follows: 1. Navigate to /posts 2. Search for "test" 3. Navigate to /posts again 4. Refresh the page The user should see plain post list, but instead they were seeing the "test" search results again as if step 3 never happened.
This commit is contained in:
parent
467b4a7630
commit
fea9a94945
4 changed files with 13 additions and 9 deletions
|
@ -1,6 +1,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const config = require('../config.js');
|
const config = require('../config.js');
|
||||||
|
const router = require('../router.js');
|
||||||
const api = require('../api.js');
|
const api = require('../api.js');
|
||||||
const settings = require('../models/settings.js');
|
const settings = require('../models/settings.js');
|
||||||
const uri = require('../util/uri.js');
|
const uri = require('../util/uri.js');
|
||||||
|
@ -54,9 +55,7 @@ class PostListController {
|
||||||
}
|
}
|
||||||
|
|
||||||
_evtNavigate(e) {
|
_evtNavigate(e) {
|
||||||
history.pushState(
|
router.showNoDispatch(
|
||||||
null,
|
|
||||||
window.title,
|
|
||||||
uri.formatClientLink('posts', e.detail.parameters));
|
uri.formatClientLink('posts', e.detail.parameters));
|
||||||
Object.assign(this._ctx.parameters, e.detail.parameters);
|
Object.assign(this._ctx.parameters, e.detail.parameters);
|
||||||
this._syncPageController();
|
this._syncPageController();
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const router = require('../router.js');
|
||||||
const api = require('../api.js');
|
const api = require('../api.js');
|
||||||
const uri = require('../util/uri.js');
|
const uri = require('../util/uri.js');
|
||||||
const TagList = require('../models/tag_list.js');
|
const TagList = require('../models/tag_list.js');
|
||||||
|
@ -46,9 +47,7 @@ class TagListController {
|
||||||
}
|
}
|
||||||
|
|
||||||
_evtNavigate(e) {
|
_evtNavigate(e) {
|
||||||
history.pushState(
|
router.showNoDispatch(
|
||||||
null,
|
|
||||||
window.title,
|
|
||||||
uri.formatClientLink('tags', e.detail.parameters));
|
uri.formatClientLink('tags', e.detail.parameters));
|
||||||
Object.assign(this._ctx.parameters, e.detail.parameters);
|
Object.assign(this._ctx.parameters, e.detail.parameters);
|
||||||
this._syncPageController();
|
this._syncPageController();
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const api = require('../api.js');
|
const api = require('../api.js');
|
||||||
|
const router = require('../router.js');
|
||||||
const uri = require('../util/uri.js');
|
const uri = require('../util/uri.js');
|
||||||
const UserList = require('../models/user_list.js');
|
const UserList = require('../models/user_list.js');
|
||||||
const topNavigation = require('../models/top_navigation.js');
|
const topNavigation = require('../models/top_navigation.js');
|
||||||
|
@ -38,9 +39,7 @@ class UserListController {
|
||||||
}
|
}
|
||||||
|
|
||||||
_evtNavigate(e) {
|
_evtNavigate(e) {
|
||||||
history.pushState(
|
router.showNoDispatch(
|
||||||
null,
|
|
||||||
window.title,
|
|
||||||
uri.formatClientLink('users', e.detail.parameters));
|
uri.formatClientLink('users', e.detail.parameters));
|
||||||
Object.assign(this._ctx.parameters, e.detail.parameters);
|
Object.assign(this._ctx.parameters, e.detail.parameters);
|
||||||
this._syncPageController();
|
this._syncPageController();
|
||||||
|
|
|
@ -158,6 +158,13 @@ class Router {
|
||||||
window.removeEventListener('popstate', this._onPopState, false);
|
window.removeEventListener('popstate', this._onPopState, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
showNoDispatch(path, state) {
|
||||||
|
const ctx = new Context(path, state);
|
||||||
|
ctx.pushState();
|
||||||
|
this.ctx = ctx;
|
||||||
|
return ctx;
|
||||||
|
}
|
||||||
|
|
||||||
show(path, state, push) {
|
show(path, state, push) {
|
||||||
const ctx = new Context(path, state);
|
const ctx = new Context(path, state);
|
||||||
const oldPath = this.ctx ? this.ctx.path : ctx.path;
|
const oldPath = this.ctx ? this.ctx.path : ctx.path;
|
||||||
|
|
Loading…
Reference in a new issue