I am currently developing a players module. Within this module, there are 3 routing cards on the initial page. Each card leads to the next page, which contains multiple routing cards related to their parent card.
For Example:
1. 1st level Card(Player Name) --> 2nd level Cards(Players Info, Player Statistics, Records) --> up to 3rd level routing
2. 1st level Card(Grounds) --> 2nd level Cards(Grounds Info, Match played, Records) --> up to 3rd level routing
3. 1st level Card(Match Information) --> 2nd level Cards(Match info, match history, community resources) --> up to 3rd level routing
Now, I have created components with respective routes for all these. However, I want to create one component to handle routing based on conditions ($route.path).
Below is my routes.js file:
{
name: 'Players',
path: '/players',
component: PageLayout,
meta: {
topNavigation: true
},
redirect: { path: '/players/entry' },
children: [
{
name: 'PlayersEntryPage',
path: 'entry',
component: PlayersEntryPage
},
{
name: 'PlayersName',
path: 'name',
component: PlayersName
},
{
name: 'Grounds',
path: 'grounds',
component: Grounds
},
{
name: 'MatchInformation',
path: 'info',
component: MatchInformation
}
]
}
This is the homepage and the 1st level subsequent card components for routing:
PlayersEntryPage
<template>
<vu-page background="gray">
<vu-container>
<vu-row-control class="mt-3">
<vu-box-control :list="cardLists" @click="cardAction"></vu-box-control>
</vu-row-control>
</vu-container>
</vu-page>
</template>
<script>
export default {
data() {
return {
cardLists: [
{ heading: ‘PlName', content:’Players Name and information',to:'/players/name'},
{ heading: ‘Grnd', content: ‘Ground Information', to:'/players/grounds' },
{ heading: ‘Infos', content: ‘Match Informations', to:'/players/info' }
]
};
},
methods: {
cardAction(value) {
if(value) {
this.$router.push(value.to);
}
}
}
};
</script>
1st level component (PlayersName) -> 2nd level component cards
<template>
<vu-page background="gray">
<vu-container>
<vu-row-control class="mt-3">
<vu-box-control :list="cardLists" @click="cardAction"></vu-box-control>
</vu-row-control>
</vu-container>
</vu-page>
</template>
<script>
export default {
data() {
return {
cardLists: [
{ heading: ‘Players Personal Info', to:’/players/name/pinfo'},
{ heading: ‘Players Statistics', to:'/players/name/statistics' },
{ heading: ‘Players Records',to:’/players/name/records' }
]
};
},
methods: {
cardAction(value) {
if(value) {
this.$router.push(value.to);
}
}
}
};
</script>
Box-control code snippet
<template>
<div class="box-wrapper">
<div v-for="(items, i) in boxes" :key="'box-row-' + i" class="box-container">
<vu-button-control
v-for="item in items"
:key="item.heading"
plain
class="box"
:to="item.to"
@click="click($event, item)"
>
<vu-row-control>
<vu-column-control cols="10">
<h1 class="label">{{ item.heading }}</h1>
<p class="body_content">{{ item.content }}</p>
</vu-column-control>
<vu-column-control cols="2">
<vu-button-control @click.stop=“addFavouriteClick(item)”>
</vu-button-control>
</vu-column-control>
</vu-row-control>
</vu-button-control>
</div>
</div>
</template>
All other routing cards follow the same structure, with only differences in the passed data. This is why I want a single component that can handle different routes based on the $route path.
I am considering using a switch case approach but struggling with the conditional routing part.