matched: [{ components: { foo: components.Foo }, path: '/' }],
},
withParams: {
- fullPath: '/users/3',
+ fullPath: '/users/1',
name: undefined,
- path: '/users/3',
+ path: '/users/1',
query: {},
params: { id: '1' },
hash: '',
},
],
},
+ withIdAndOther: {
+ fullPath: '/props/1',
+ name: undefined,
+ path: '/props/1',
+ query: {},
+ params: { id: '1' },
+ hash: '',
+ meta: {},
+ matched: [
+ {
+ components: { default: components.WithProps },
+ path: '/users/:id',
+ props: { id: 'foo', other: 'fixed' },
+ },
+ ],
+ },
})
describe('RouterView', () => {
await tick()
expect(el.innerHTML).toBe(`<div>User: 4</div>`)
})
+
+ it('can pass an object as props', async () => {
+ const { el } = factory(routes.withIdAndOther)
+ expect(el.innerHTML).toBe(`<div>id:foo;other:fixed</div>`)
+ })
})
return h('div', {}, 'User: ' + this.id)
},
}),
+ WithProps: defineComponent({
+ props: {
+ id: {
+ default: 'default',
+ },
+ other: {
+ default: 'other',
+ },
+ },
+ render() {
+ return h('div', {}, `id:${this.id};other:${this.other}`)
+ },
+ }),
Nested: {
render: () => {
const RouterView = resolveComponent('RouterView')
)
const propsData = computed(() => {
- if (!matchedRoute.value.props) return {}
+ const { props } = matchedRoute.value
+ if (!props) return {}
+ if (props === true) return route.value.params
- return route.value.params
+ return props
})
provide(matchedRouteKey, matchedRoute)
path: string
alias?: string | string[]
name?: string
- props?: boolean
+ props?: boolean | Record<string, any>
// TODO: beforeEnter has no effect with redirect, move and test
beforeEnter?: NavigationGuard | NavigationGuard[]
meta?: Record<string | number | symbol, any>