From fb2d4487f3bf64e62e9a0b0ccfda886e1eb2d878 Mon Sep 17 00:00:00 2001 From: viown <48097677+viown@users.noreply.github.com> Date: Sun, 6 Oct 2024 16:10:27 +0300 Subject: [PATCH] Fix UI freeze when opening same path --- src/components/router/appRouter.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/components/router/appRouter.js b/src/components/router/appRouter.js index bbd2a8b2416..6e156073b33 100644 --- a/src/components/router/appRouter.js +++ b/src/components/router/appRouter.js @@ -39,6 +39,9 @@ class AppRouter { constructor() { document.addEventListener('viewshow', () => this.onViewShow()); + this.lastPath = history.location.pathname + history.location.search; + this.listen(); + // TODO: Can this baseRoute logic be simplified? this.baseRoute = window.location.href.split('?')[0].replace(this.#getRequestFile(), ''); // support hashbang @@ -100,6 +103,20 @@ class AppRouter { return this.promiseShow; } + listen() { + history.listen(({ location }) => { + const normalizedPath = location.pathname.replace(/^!/, ''); + const fullPath = normalizedPath + location.search; + + if (fullPath === this.lastPath) { + console.debug('[appRouter] path did not change, resolving promise'); + this.onViewShow(); + } + + this.lastPath = fullPath; + }); + } + baseUrl() { return this.baseRoute; }