Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/components/RouterView.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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: {
Expand Down
5 changes: 3 additions & 2 deletions src/router/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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]
Expand Down