Skip to content

Commit 1155434

Browse files
committed
test: boiling down repro
1 parent b17be85 commit 1155434

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed

playground/router.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Nested from './views/Nested.vue'
44
import NestedWithId from './views/NestedWithId.vue'
55
import Dynamic from './views/Dynamic.vue'
66
import User from './views/User.vue'
7+
import Increment from './views/Increment.vue'
78
import NotFound from './views/NotFound.vue'
89
const component = () => {
910
console.log('fetching component')
@@ -35,6 +36,12 @@ export const router = createRouter({
3536
params: { id: String(Math.round(Math.random() * 100)) },
3637
}),
3738
},
39+
{
40+
path: '/bug/:increment',
41+
name: 'inc',
42+
component: Increment,
43+
props: route => ({ increment: route.params.increment }),
44+
},
3845
{ path: '/users/:id', name: 'user', component: User, props: true },
3946
{ path: '/documents/:id', name: 'docs', component: User, props: true },
4047
{ path: '/optional/:id?', name: 'optional', component: User, props: true },

playground/views/ChildComponent.vue

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<template>
2+
<div>{{ injected }}</div>
3+
<router-link :to="newLocation">Increment {{ injected }}</router-link>
4+
</template>
5+
6+
<script>
7+
import { inject, watch, computed } from 'vue'
8+
export default {
9+
name: 'ChildComponent',
10+
setup() {
11+
const injected = inject('increment')
12+
13+
watch(injected, () => {
14+
console.log('route param changed', injected.value)
15+
})
16+
17+
const newLocation = computed(() => ({
18+
name: 'inc',
19+
params: { increment: Number(injected.value) + 1 },
20+
}))
21+
22+
return {
23+
injected,
24+
newLocation,
25+
}
26+
},
27+
}
28+
</script>

playground/views/Increment.vue

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<template>
2+
<div>
3+
<!-- <router-link
4+
:to="{ name: 'inc', params: { increment: Number(increment) + 1 } }"
5+
>Increment at root</router-link
6+
> -->
7+
<child-component />
8+
<child-component />
9+
<div style="height: 200px"></div>
10+
</div>
11+
</template>
12+
13+
<script>
14+
import { provide, toRef, toRefs, watchEffect } from 'vue'
15+
import ChildComponent from './ChildComponent.vue'
16+
import { useRoute, useRouter } from '../../src'
17+
18+
export default {
19+
components: { ChildComponent },
20+
name: 'ProvideComponent',
21+
props: ['increment'],
22+
setup(props) {
23+
const increment = toRef(props, 'increment')
24+
const route = useRoute()
25+
const router = useRouter()
26+
27+
provide('increment', increment)
28+
29+
watchEffect(() => {
30+
console.log('prop', increment.value)
31+
})
32+
33+
watchEffect(() => {
34+
console.log(
35+
'router.currentRoute',
36+
router.currentRoute.value.params.increment
37+
)
38+
})
39+
40+
watchEffect(() => {
41+
console.log('route.params', route.params.increment)
42+
})
43+
44+
return { increment }
45+
},
46+
}
47+
</script>

0 commit comments

Comments
 (0)