feat: Optionally skip passing focus to RouterView on navigate #433
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In our application we've got a navigation bar that sits about the RouterView in our App component, the idea being that this navigation bar is available on every page, and has the logic to navigate between them while remaining visible the whole time.
We have a pain point with the current router implementation when navigating between pages in that anytime you use
$router.to, focus automatically gets passed to the RouterView and then along to the page component. For us this means that our nav gets unfocused every time we swap pages rather than what we need which is for the nav bar to remain in focus until you scroll down into a page.To support this use case, I've added a check for a
passFocusoption when navigating. This won't affect the current logic when unused, but if set tofalseas part of the router options, the current focus will not change when navigating.Example:
this.$router.to('home', {id: 123456}, {passFocus: false});This would prevent us needing to constantly fight the current focus and try and refocus the nav when going between pages