Skip to content

Commit 36ce2ef

Browse files
committed
docs(TabStrip): add tabstrip dynamic routes KB
1 parent d7a2b51 commit 36ce2ef

File tree

5 files changed

+144
-0
lines changed

5 files changed

+144
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<template>
2+
<article>This is tab 1!</article>
3+
</template>
4+
5+
<script>
6+
export default {
7+
name: 'TabOne',
8+
};
9+
</script>
10+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<template>
2+
<article>This is tab 2!</article>
3+
</template>
4+
5+
<script>
6+
export default {
7+
name: 'TabTwo',
8+
};
9+
</script>
10+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { createApp } from 'vue';
2+
import App from './main.vue';
3+
import TabOne from './TabOne.vue';
4+
import TabTwo from './TabTwo.vue';
5+
import { createRouter, createWebHistory } from 'vue-router';
6+
7+
const routes = [
8+
{
9+
path: '/tab1',
10+
name: 'Tab1',
11+
component: TabOne,
12+
},
13+
{
14+
path: '/tab2',
15+
name: 'Tab2',
16+
component: TabTwo,
17+
},
18+
];
19+
20+
const router = createRouter({
21+
routes,
22+
history: createWebHistory(),
23+
});
24+
25+
createApp(App).use(router).mount('#app');
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<template>
2+
<TabStrip
3+
:selected="selected"
4+
:animation="false"
5+
@select="onSelect"
6+
:tabs="tabs"
7+
>
8+
<template #content>
9+
<RouterView v-slot="slotProps">
10+
<Component :is="slotProps.Component" />
11+
</RouterView>
12+
</template>
13+
</TabStrip>
14+
</template>
15+
16+
<script>
17+
import { ref, watchEffect } from 'vue';
18+
import { TabStrip } from '@progress/kendo-vue-layout';
19+
import { RouterView, useRouter, useRoute } from 'vue-router';
20+
21+
export default {
22+
components: {
23+
TabStrip,
24+
RouterView,
25+
},
26+
setup() {
27+
const route = useRoute();
28+
const router = useRouter();
29+
const selected = ref(0);
30+
const tabs = [
31+
{
32+
title: 'Tab 1',
33+
content: 'content',
34+
pathName: 'Tab1',
35+
},
36+
{
37+
title: 'Tab 2',
38+
content: 'content',
39+
pathName: 'Tab2',
40+
},
41+
];
42+
watchEffect(() => {
43+
selected.value = tabs.findIndex((tab) => tab.pathName === route.name);
44+
});
45+
function onSelect(event) {
46+
router.push({
47+
name: tabs[event.selected].pathName,
48+
});
49+
}
50+
51+
return {
52+
selected,
53+
tabs,
54+
onSelect,
55+
};
56+
},
57+
};
58+
</script>
59+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
title: Add dynamic routes to the TabStrip
3+
description: An example on how to add dynamic routes to the TabStrip
4+
type: how-to
5+
page_title: Add Dynamic Routes to the TabStrip - Kendo UI for Vue Native TabStrip
6+
slug: tabstrip-add-dynamic-routes
7+
tags: tabstrip, routes, dynamic, kendovue
8+
res_type: kb
9+
category: knowledge-base
10+
---
11+
12+
## Environment
13+
14+
<table>
15+
<tbody>
16+
<tr>
17+
<td>Product Version</td>
18+
<td>4.3.1</td>
19+
</tr>
20+
<tr>
21+
<td>Product</td>
22+
<td>Progress® Kendo UI for Vue Native</td>
23+
</tr>
24+
</tbody>
25+
</table>
26+
27+
## Description
28+
29+
This Knowledge base(KB) article shows how you can set dynamic routes to the TabStrip component.
30+
31+
## Solution
32+
33+
This can be achieved by binding the selected tab to the current route, users can navigate between tabs with their content dynamically loaded based on the URL.
34+
35+
{% meta id:index height:400 %}
36+
{% embed_file tabstrip-dynamic-routes/main.vue preview %}
37+
{% embed_file tabstrip-dynamic-routes/main.js %}
38+
{% embed_file tabstrip-dynamic-routes/TabOne.vue %}
39+
{% embed_file tabstrip-dynamic-routes/TabTwo.vue %}
40+
{% endmeta %}

0 commit comments

Comments
 (0)