matched: [
{
components: { default: components.WithProps },
- path: '/users/:id',
+ path: '/props/:id',
props: { id: 'foo', other: 'fixed' },
},
],
},
+
+ withFnProps: {
+ fullPath: '/props/1',
+ name: undefined,
+ path: '/props/1',
+ query: { q: 'page' },
+ params: { id: '1' },
+ hash: '',
+ meta: {},
+ matched: [
+ {
+ components: { default: components.WithProps },
+ path: '/props/:id',
+ props: to => ({ id: Number(to.params.id) * 2, other: to.query.q }),
+ },
+ ],
+ },
})
describe('RouterView', () => {
const { el } = factory(routes.withIdAndOther)
expect(el.innerHTML).toBe(`<div>id:foo;other:fixed</div>`)
})
+
+ it('can pass a function as props', async () => {
+ const { el } = factory(routes.withFnProps)
+ expect(el.innerHTML).toBe(`<div>id:2;other:page</div>`)
+ })
})
if (!props) return {}
if (props === true) return route.value.params
- return props
+ return typeof props === 'object' ? props : props(route.value)
})
provide(matchedRouteKey, matchedRoute)
path: string
alias?: string | string[]
name?: string
- props?: boolean | Record<string, any>
+ props?:
+ | boolean
+ | Record<string, any>
+ | ((to: RouteLocationNormalized) => Record<string, any>)
// TODO: beforeEnter has no effect with redirect, move and test
beforeEnter?: NavigationGuard | NavigationGuard[]
meta?: Record<string | number | symbol, any>