question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bug: ionic vue, not updating params when getting viewitem on route with params

See original GitHub issue

After version 5.5.2 Only the first time a route is rendered does the prop get updated. Subsequent calls to the same component with a different route property continue to only render with the original property. This manifests itself when utilizing a list, detail, back-to-list pattern (for example Client List & Client Detail in a CRM app).

Ionic version: 5.5.3 and onward. 5.5.2 worked correctly.

Current behavior: router.push(‘/mycomponent/1’) - the first time the component recognizes the prop as “1”. router.push(‘/mycomponent/2’) - the second time the component continues to only see prop as “1”

Expected behavior: The props should be updated so that the component can update the view based on the revised route

Related code: Sample code based on the default example app

Router:

import { createRouter, createWebHistory } from '@ionic/vue-router';
import { RouteRecordRaw } from 'vue-router';
import Home from '../views/Home.vue'
import TestView from '../views/TestView.vue';

const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    redirect: '/home'
  },
  {
    path: '/home',
    name: 'Home',
    component: Home
  },
  {
    path: '/test/:id',
    name: 'TestView',
    component: TestView,
    props: true,
  }
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

export default router

Home

<template>
	<ion-page>
		<ion-content :fullscreen="true">
			<div id="container">
				<div @click="$router.push(`/test/1`)" style="cursor: pointer; margin-bottom: 10px">Test ID 1</div>
				<div @click="$router.push(`/test/2`)" style="cursor: pointer; margin-bottom: 10px">Test ID 2</div>
				<div @click="$router.push(`/test/3`)" style="cursor: pointer; margin-bottom: 10px">Test ID 3</div>
			</div>
		</ion-content>
	</ion-page>
</template>

<script lang="ts">
import {IonContent, IonPage} from '@ionic/vue';
import {defineComponent} from 'vue';

export default defineComponent({
	name: 'Home',
	components: {
		IonContent,
		IonPage,
	},
});
</script>

Test View

<template>
	<ion-page
	><ion-header>
		<ion-toolbar>
			<ion-buttons slot="start">
				<ion-back-button></ion-back-button>
			</ion-buttons>
			<ion-title>ID: {{id}}</ion-title>
		</ion-toolbar>
	</ion-header>
	</ion-page>
</template>

<script>
import {defineComponent} from 'vue';
import {
	IonPage,
	IonHeader,
	IonToolbar,
	IonButtons,
	IonTitle,
	IonBackButton,
} from '@ionic/vue';

export default defineComponent({
	name: 'TestView',

	props: ['id'],

	components: {
		IonPage,
		IonHeader,
		IonToolbar,
		IonButtons,
		IonTitle,
		IonBackButton,
	},
});
</script>

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
geoffreymina13commented, Mar 15, 2021

Thanks for working so quickly, Liam! Function mode is working now in 5.7.0-dev.202103151643.8d8c811.

Awesome first experience submitting an issue to you guys. Thanks for all you do!

1reaction
liamdebeasicommented, Mar 15, 2021

Ok thanks. Can you give this dev build a shot and see if the props get updated using function mode?

npm install @ionic/vue@5.7.0-dev.202103151643.8d8c811 @ionic/vue-router@5.7.0-dev.202103151643.8d8c811
Read more comments on GitHub >

github_iconTop Results From Across the Web

bug: ionic vue, not updating params when getting viewitem on ...
After version 5.5.2 Only the first time a route is rendered does the prop get updated. Subsequent calls to the same component with...
Read more >
ionic/vue-router: Props not updating from route
Hi all, using @ionic/vue for a project. Need routes that point to specific displays of an object. Got that part working: In routes:...
Read more >
Vue Router params not updating in page - Stack Overflow
Try adding :key to your Component to make sure it updates when param changes: <your-component :key="$route.params.
Read more >
Getting started with Ionic 5 and Vue - Aveek Saha
A beginners guide on how to build a mobile application with Ionic and Vue.
Read more >
Angular Component Inside Of Router-Outlet On Child Route ...
For a general introduction to angular see the Getting Started. The router outlet serves as a placeholder where the routed components are rendered....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found