I'm using VueJS. I have externally generated markdowns, and I want to generate static pages out of them thanks to a vue component. I'm using the vite-plugin-md
to convert imported md files into a component.
Working example
Config (vite.config.js
)
import Markdown from "vite-plugin-vue-markdown"
The router (index.ts
)
{
path: "/my_page_1",
name: "My Page 1",
component: () => import("@/pages/markdown.vue"),
}
The component (markdown.vue
)
<template>
<MardownPage/>
</template>
<script lang="ts" setup>
import MardownPage from "@/assets/markdown/my_page_1.md"
</script>
Expected behavior
In the working example, the component is tied to a unique markdown.
I actually want to use the same component for many different markdown pages. I feel the expected way to do this is to have something like the following in the router :
{
path: "/my_page_1",
name: "My Page 1",
component: () => import("@/pages/markdown.vue"),
meta: {
path: "@/assets/markdown/page_1.md",
},
},
{
path: "/my_page_2",
name: "My Page 2",
component: () => import("@/pages/markdown.vue"),
meta: {
path: "@/assets/markdown/page_2.md",
},
}
Current (non-working) behavior
On the component side, I've written the following
import {useRoute} from "vue-router";
import { defineAsyncComponent } from 'vue'
const route = useRoute();
console.log(route.meta.path);
const AsyncComp = defineAsyncComponent(() =>
import(route.meta.path)
)
While the path appears in the console, it does return an error related to the dynamic importation of the module (error loading dynamically imported module
).
I've tested many options related to lazy loading, dynamic routes, promises, ... (which I'm not 100% familiar and skilled with) but haven't worked my way around to do so.