I am encountering an issue that I have reproduced with the following simplified code:
App.vue
<router-link to="/">Home</router-link> |
<router-link :to="{name: 'View1', params: {myprop: 'hello 1'}}"> |
View 1 - Param 1
</router-link>
<router-link :to="{name: 'View1', params: {myprop: 'hello 2'}}"> |
View 1 - Param 2
</router-link>
<router-view :key='$route.path' />
View1.vue
<template>
<div>
My prop = {{myprop}}
</div>
</template>
If I start on the Home link and click “View 1 - Param 1”, I am taken to View1 and see “My prop = hello 1”. This is as expected.
If I then go back to the home page and click “View 1 - Param 2”, I am taken to View1 and see “My prop = hello 2”. This is also as expected.
Here’s where the trouble starts. If I click “View 1 - Param 1” while I am already on “View 1 - Param 2”, then I am taken to View1, but the message does not update. So, I see “My prop = hello 2” again instead of seeing “My prop = hello 1”.
My understanding is that Vue is not rerendering View1 as an optimization since the “from” view and “to” view are the same, but clearly that is not the behavior I would like.
I did some research on this and came across a video that suggested using “key=’$route.path’” in the view tag would address this. However, this is not solving the issue for me.
What is the correct way to address this issue, please?