From 56756870a6c3055b82e50d064499f1ff99b73d95 Mon Sep 17 00:00:00 2001 From: Matt Wooding <44930483+WoodingMP@users.noreply.github.com> Date: Wed, 30 Jul 2025 13:49:52 +0100 Subject: [PATCH] feat: add passFocus option to router to prevent focusing RouterView on navigate --- docs/router/basics.md | 2 ++ src/router/router.js | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/router/basics.md b/docs/router/basics.md index c25279f1..1576c1be 100644 --- a/docs/router/basics.md +++ b/docs/router/basics.md @@ -96,6 +96,8 @@ export default Blits.Component('Poster', { Whenever you navigate to a new page, the URL hash will automatically be updated. Unless specified otherwise, navigating to a new page, will add that route to the history stack. The `back` input action is automatically wired up to navigate back down the history stack. +By default, every time you navigate to a new route, the application focus will be automatically passed to the newly loaded page. If you instead want to maintain the current focus (for example in a widget that sits above your RouterView), you can use `passFocus: false` as part of the router options. + ## Deeplinking The Router plugin has support for deeplinking. When the App is loaded with a URL hash (i.e. `#/pages/settings/network`), the router will try to match that hash to a defined route. This means that your app can be deep linked into, by simply providing the correct URL hash. diff --git a/src/router/router.js b/src/router/router.js index 97049434..29dc32a7 100644 --- a/src/router/router.js +++ b/src/router/router.js @@ -337,8 +337,10 @@ export const navigate = async function () { // keep reference to the previous focus for storing in cache previousFocus = Focus.get() - // set focus to the view that we're routing to - focus ? focus.$focus() : /** @type {BlitsComponent} */ (view).$focus() + // set focus to the view that we're routing to (unless explicitly disabling passing focus) + if (route.options.passFocus !== false) { + focus ? focus.$focus() : /** @type {BlitsComponent} */ (view).$focus() + } // apply before settings to holder element if (route.transition.before) {