Skip to content

preloadRouteComponents allows passing values of type RouteLocationRaw #18845

Description

@Mini-ghost

Describe the feature

Currently, preloadRouteComponents() only allows the first parameter to be a string, but sometimes we may pass an object for to of <NuxtLink />. This can cause many of the same routes path to be considered not preloaded, like bellow:

<!-- Passing a string -->
<NuxtLink to="/home"> Home </NuxtLink>

<!-- Passing a string with query string -->
<!-- `router.resolve('/home?year=2023').path` is `/home` -->
<NuxtLink to="/home?year=2023"> Home </NuxtLink>

<!-- Passing a object -->
<!-- `router.resolve({ name: 'home', query: { year: '2023' } }).path` is `/home` -->
<NuxtLink :to="{ name: 'home', query: { year: '2023' } }"> Home </NuxtLink>

These routing paths are all '/home', but all of them will run preload without early return, although the request will not actually be sent.


Maybe we can allow passing an object or string of type RouteLocationRaw and use the path returned by router.resolve() as the preloaded record?

The preloadRouteComponents() will like bellow:

function preloadRouteComponents(to: RouteLocationRaw, router?: Router): Promise<void>

I don't know if it fits the core team's thinking.

Additional information

  • Would you be willing to help implement this feature?
  • Could this feature be implemented as a module?

Final checks

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions