diff options
| author | rr- | 2017-04-24 23:02:25 +0200 |
|---|---|---|
| committer | rr- | 2017-04-24 23:02:25 +0200 |
| commit | fea9a949453482f7ede7957dbeeddb3c2ff427cc (patch) | |
| tree | 3b6358f4026f41a4d87f6ae89f5f8b4f699088e7 /client | |
| parent | 467b4a76308b2fc4478dd3586e6339c88cc499b2 (diff) | |
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.
Diffstat (limited to 'client')
| -rw-r--r-- | client/js/controllers/post_list_controller.js | 5 | ||||
| -rw-r--r-- | client/js/controllers/tag_list_controller.js | 5 | ||||
| -rw-r--r-- | client/js/controllers/user_list_controller.js | 5 | ||||
| -rw-r--r-- | client/js/router.js | 7 |
4 files changed, 13 insertions, 9 deletions
diff --git a/client/js/controllers/post_list_controller.js b/client/js/controllers/post_list_controller.js index c857742..4fce8ea 100644 --- a/client/js/controllers/post_list_controller.js +++ b/client/js/controllers/post_list_controller.js @@ -1,6 +1,7 @@ 'use strict'; const config = require('../config.js'); +const router = require('../router.js'); const api = require('../api.js'); const settings = require('../models/settings.js'); const uri = require('../util/uri.js'); @@ -54,9 +55,7 @@ class PostListController { } _evtNavigate(e) { - history.pushState( - null, - window.title, + router.showNoDispatch( uri.formatClientLink('posts', e.detail.parameters)); Object.assign(this._ctx.parameters, e.detail.parameters); this._syncPageController(); diff --git a/client/js/controllers/tag_list_controller.js b/client/js/controllers/tag_list_controller.js index 2598143..3b4bd3e 100644 --- a/client/js/controllers/tag_list_controller.js +++ b/client/js/controllers/tag_list_controller.js @@ -1,5 +1,6 @@ 'use strict'; +const router = require('../router.js'); const api = require('../api.js'); const uri = require('../util/uri.js'); const TagList = require('../models/tag_list.js'); @@ -46,9 +47,7 @@ class TagListController { } _evtNavigate(e) { - history.pushState( - null, - window.title, + router.showNoDispatch( uri.formatClientLink('tags', e.detail.parameters)); Object.assign(this._ctx.parameters, e.detail.parameters); this._syncPageController(); diff --git a/client/js/controllers/user_list_controller.js b/client/js/controllers/user_list_controller.js index 16f3b9b..fa878d8 100644 --- a/client/js/controllers/user_list_controller.js +++ b/client/js/controllers/user_list_controller.js @@ -1,6 +1,7 @@ 'use strict'; const api = require('../api.js'); +const router = require('../router.js'); const uri = require('../util/uri.js'); const UserList = require('../models/user_list.js'); const topNavigation = require('../models/top_navigation.js'); @@ -38,9 +39,7 @@ class UserListController { } _evtNavigate(e) { - history.pushState( - null, - window.title, + router.showNoDispatch( uri.formatClientLink('users', e.detail.parameters)); Object.assign(this._ctx.parameters, e.detail.parameters); this._syncPageController(); diff --git a/client/js/router.js b/client/js/router.js index 64f467e..a8bd4c3 100644 --- a/client/js/router.js +++ b/client/js/router.js @@ -158,6 +158,13 @@ class Router { 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) { const ctx = new Context(path, state); const oldPath = this.ctx ? this.ctx.path : ctx.path; |