Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

What problem is this solving

Enable precise control over cached component instances when combining RouterView with KeepAlive.

For instance, when the route.path is /user/:id, distinct component instances can be mapped based on the fullPath parameter.

Proposed solution

By configuring RouterView props, the underlying component exposed via its default slot can be wrapped, allowing distinct component instances to be provided to KeepAlive for fine-grained control over route cache behavior.

Describe alternatives you've considered

I've implemented this feature by wrapping the Component from the RouterView slot, and released it as a package named vue-router-better-view. The component accepts a resolveViewKey prop to customize the name of the wrapped component used by KeepAlive. If not provided, it behaves identically to the original RouterView. Aside from a minor difference in template refs handling, the usage remains fully compatible. Would such a feature be considered for inclusion in the official Vue Router implementation?

You must be logged in to vote

Replies: 1 comment

Comment options

Nice library! This is a "cool show and tell" so I will move it there.
KeepAlive shouldn't need a specific integration with the Router because it should be flexible enough to work with a component and props. The v-slot API can be adapted with a custom wrapper for customization if needed.

There are some open issues and RFCs about KeepAlive already that you might want to participate in

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #2507 on May 30, 2025 06:53.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.