diff --git a/src/components/RouterView.js b/src/components/RouterView.js index 296e099a..f6a3d97a 100644 --- a/src/components/RouterView.js +++ b/src/components/RouterView.js @@ -18,6 +18,7 @@ import Component from '../component.js' import Router from '../router/router.js' import symbols from '../lib/symbols.js' +import Focus from '../focus.js' let hashchangeHandler = null @@ -44,7 +45,9 @@ export default () => window.removeEventListener('hashchange', hashchangeHandler, false) }, focus() { - this.activeView && this.activeView.$focus() + if (this.activeView && Focus.get() === this) { + this.activeView.$focus() + } }, }, input: { diff --git a/src/router/router.js b/src/router/router.js index 871e1d17..3e7c0a9c 100644 --- a/src/router/router.js +++ b/src/router/router.js @@ -337,6 +337,9 @@ export const navigate = async function () { // keep reference to the previous focus for storing in cache previousFocus = Focus.get() + const children = this[symbols.children] + this.activeView = children[children.length - 1] + // set focus to the view that we're routing to focus ? focus.$focus() : /** @type {BlitsComponent} */ (view).$focus() @@ -380,8 +383,6 @@ export const navigate = async function () { await setOrAnimate(holder, route.transition.in, shouldAnimate) } } - const children = this[symbols.children] - this.activeView = children[children.length - 1] } else { Log.error(`Route ${hash} not found`) const routerHooks = this.parent[symbols.routerHooks]