@esmx/router-vue
Version:
Vue integration for @esmx/router - A universal router that works seamlessly with both Vue 2.7+ and Vue 3
18 lines (17 loc) • 616 B
JavaScript
import { defineComponent, h, inject, provide } from "vue";
import { useRoute } from "./use.mjs";
import { resolveComponent } from "./util.mjs";
const RouterViewDepthKey = Symbol("RouterViewDepth");
export const RouterView = defineComponent({
name: "RouterView",
setup() {
const route = useRoute();
const depth = inject(RouterViewDepthKey, 0);
provide(RouterViewDepthKey, depth + 1);
return () => {
const matchedRoute = route.matched[depth];
const component = matchedRoute ? resolveComponent(matchedRoute.component) : null;
return component ? h(component) : null;
};
}
});