Skip to content

Expose a function to resolve a RouteLocationNormalized into a RouteLocationNormalizedLoaded that can be used by <RouterView/> #1048

Closed
@7architect

Description

@7architect

Version

4.0.10

Reproduction link

https://codesandbox.io/s/elastic-kilby-3461t?file=/src/pages/dialog.vue

Steps to reproduce

1 - Define two async routes

import dialog from "./pages/dialog.vue";

const routes = [
  {
    name: "index",
    path: "/",

    component: () => import("./pages/main.vue")
  },
  {
    name: "dialog",
    path: "/dialog",
    // uncomment to fix
    // component: dialog,
    component: () => import("./pages/dialog.vue")
  }
];

2 - Use manually route resolve via "router.resolve"

    const router = useRouter();

    const dialogRoute = shallowRef();
    const mainRoute = shallowRef({ matched: [] });
    router.beforeResolve(() => {
      // ... if (true === route.meta.dialog)
      dialogRoute.value = router.resolve("/dialog");
      // ... some logic for read last visited route name from localStorage and resolve it
      // id "background"
      mainRoute.value = router.resolve("/");
    });

3 - Display routes via router-view slot api

  <router-view :route="mainRoute" v-slot="{ Component }">
    <template v-if="Component">
      <suspense>
        <component :is="Component" />
        <template #fallback> loading </template>
      </suspense>
    </template>
  </router-view>

  <router-view :route="dialogRoute" v-slot="{ Component }">
    <template v-if="Component">
      <suspense v-if="Component">
        <Dialog>
          <component :is="Component" />
        </Dialog>
      </suspense>
    </template>
  </router-view>

What is expected?

"dialogRoute" displayed when route assigned as async component

What is actually happening?

"dialogRoute" does not displayed and Vue throws warn

For fix "/" route shouldn't be asynchronous (uncomment rows in main.js to see fix)

[Vue warn]: Invalid VNode type: undefined (undefined)
at <Component onVnodeUnmounted=fn ref=Ref>
at
at <RouterView route= {fullPath: "/dialog", path: "/dialog", query: Object, hash: "", name: "dialog"…}>
at

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions