[Vuejs]-Vue-Router get Props from Router-Function

0👍

Ok, got the solution.

The issue is to use the Prop-Field for static values.
Now I use the meta-Property to pass the information.

<template>
    <div class="router-tabs">
        <div class="tabs">
            <router-link v-for="(route, index) in childRoutes" :key="index" class="tab" :to="route">
                <span v-if="route.meta != undefined && route.meta.label">{{ route.meta.label }}</span>
                <span v-if="route.meta == undefined || !route.meta.label">No Label</span>
            </router-link>
        </div>
        <router-view />
    </div>
</template>

<script lang="ts">
import { Component, Vue, Prop } from 'vue-property-decorator';

@Component
export default class RouterTabs extends Vue {
    public get childRoutes() {
        const childRoutes = this.$router.options.routes?.find((route) => route.name === this.$route.name || route.children?.find((child) => child.name === this.$route.name))?.children;
        return childRoutes;
    }
}
</script>

Leave a comment