fix(vue): update props when navigating to new parameterized route (#23189)

This commit is contained in:
Liam DeBeasi
2021-04-15 12:37:50 -04:00
committed by GitHub
parent 15abc181aa
commit 35c8802c22
6 changed files with 80 additions and 28 deletions

View File

@ -46,7 +46,8 @@ const routes: Array<RouteRecordRaw> = [
},
{
path: '/routing/:id',
component: () => import('@/views/RoutingParameter.vue')
component: () => import('@/views/RoutingParameter.vue'),
props: true
},
{
path: '/routing/:id/view',
@ -71,7 +72,8 @@ const routes: Array<RouteRecordRaw> = [
},
{
path: ':id',
component: () => import('@/views/Folder.vue')
component: () => import('@/views/Folder.vue'),
props: true
}
]
},

View File

@ -5,19 +5,19 @@
<ion-buttons slot="start">
<ion-menu-button></ion-menu-button>
</ion-buttons>
<ion-title>{{ folder }}</ion-title>
<ion-title>{{ $props.id }}</ion-title>
</ion-toolbar>
</ion-header>
<ion-content :fullscreen="true">
<ion-header collapse="condense">
<ion-toolbar>
<ion-title size="large">{{ folder }}</ion-title>
<ion-title size="large">{{ $props.id }}</ion-title>
</ion-toolbar>
</ion-header>
<div id="container">
<strong class="capitalize">{{ folder }}</strong>
<strong class="capitalize">{{ $props.id }}</strong>
<p>Explore <a target="_blank" rel="noopener noreferrer" href="https://ionicframework.com/docs/components">UI Components</a></p>
</div>
</ion-content>
@ -26,8 +26,6 @@
<script lang="ts">
import { IonButtons, IonContent, IonHeader, IonMenuButton, IonPage, IonTitle, IonToolbar } from '@ionic/vue';
import { useRoute } from 'vue-router';
import { ref, computed, watch } from 'vue';
export default {
name: 'Folder',
@ -40,16 +38,8 @@ export default {
IonTitle,
IonToolbar,
},
setup() {
const route = useRoute();
const folder = ref(route.params.id || 'Inbox');
const matchedFolder = computed(() => route.params.id);
watch(matchedFolder, () => {
folder.value = matchedFolder.value as string;
})
return { folder }
props: {
id: { type: String, default: 'Inbox' }
}
}
</script>

View File

@ -18,8 +18,11 @@
<ion-button id="parameter-view" :router-link="'/routing/' + $route.params.id + '/view'">Go to Single View</ion-button>
<ion-button router-link="/routing/abc">Go to Parameter Page ABC</ion-button>
<ion-button router-link="/routing/xyz">Go to Parameter Page XYZ</ion-button>
<div class="ion-padding" id="parameter-value">
{{ $route.params.id }}
{{ $props.id }}
</div>
</ion-content>
</ion-page>
@ -39,6 +42,9 @@ import {
import { defineComponent } from 'vue';
export default defineComponent({
props: {
id: { type: String, default: 'my default' }
},
components: {
IonButton,
IonBackButton,