From: Eduardo San Martin Morote Date: Tue, 26 May 2020 13:47:14 +0000 (+0200) Subject: feat: allow props for named views X-Git-Tag: v4.0.0-alpha.13~36 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dbe2344af5fed39aa4aa8fbfe48b195580d9538b;p=thirdparty%2Fvuejs%2Frouter.git feat: allow props for named views --- diff --git a/__tests__/RouterView.spec.ts b/__tests__/RouterView.spec.ts index b7e16391..cce62e4e 100644 --- a/__tests__/RouterView.spec.ts +++ b/__tests__/RouterView.spec.ts @@ -3,7 +3,10 @@ */ import { RouterView } from '../src/RouterView' import { components, RouteLocationNormalizedLoose } from './utils' -import { START_LOCATION_NORMALIZED } from '../src/types' +import { + START_LOCATION_NORMALIZED, + RouteLocationNormalized, +} from '../src/types' import { markRaw } from 'vue' import { mount, createMockedRoute } from './mount' import { mockWarn } from 'jest-mock-warn' @@ -21,6 +24,8 @@ function createRoutes>( return nonReactiveRoutes } +const props = { default: false } + const routes = createRoutes({ root: { fullPath: '/', @@ -31,7 +36,12 @@ const routes = createRoutes({ hash: '', meta: {}, matched: [ - { components: { default: components.Home }, instances: {}, path: '/' }, + { + components: { default: components.Home }, + instances: {}, + path: '/', + props, + }, ], }, foo: { @@ -43,7 +53,12 @@ const routes = createRoutes({ hash: '', meta: {}, matched: [ - { components: { default: components.Foo }, instances: {}, path: '/foo' }, + { + components: { default: components.Foo }, + instances: {}, + path: '/foo', + props, + }, ], }, nested: { @@ -55,8 +70,18 @@ const routes = createRoutes({ hash: '', meta: {}, matched: [ - { components: { default: components.Nested }, instances: {}, path: '/' }, - { components: { default: components.Foo }, instances: {}, path: 'a' }, + { + components: { default: components.Nested }, + instances: {}, + path: '/', + props, + }, + { + components: { default: components.Foo }, + instances: {}, + path: 'a', + props, + }, ], }, nestedNested: { @@ -68,9 +93,24 @@ const routes = createRoutes({ hash: '', meta: {}, matched: [ - { components: { default: components.Nested }, instances: {}, path: '/' }, - { components: { default: components.Nested }, instances: {}, path: 'a' }, - { components: { default: components.Foo }, instances: {}, path: 'b' }, + { + components: { default: components.Nested }, + instances: {}, + path: '/', + props, + }, + { + components: { default: components.Nested }, + instances: {}, + path: 'a', + props, + }, + { + components: { default: components.Foo }, + instances: {}, + path: 'b', + props, + }, ], }, named: { @@ -82,7 +122,7 @@ const routes = createRoutes({ hash: '', meta: {}, matched: [ - { components: { foo: components.Foo }, instances: {}, path: '/' }, + { components: { foo: components.Foo }, instances: {}, path: '/', props }, ], }, withParams: { @@ -99,7 +139,7 @@ const routes = createRoutes({ instances: {}, path: '/users/:id', - props: true, + props: { default: true }, }, ], }, @@ -117,7 +157,7 @@ const routes = createRoutes({ instances: {}, path: '/props/:id', - props: { id: 'foo', other: 'fixed' }, + props: { default: { id: 'foo', other: 'fixed' } }, }, ], }, @@ -136,7 +176,12 @@ const routes = createRoutes({ instances: {}, path: '/props/:id', - props: to => ({ id: Number(to.params.id) * 2, other: to.query.q }), + props: { + default: (to: RouteLocationNormalized) => ({ + id: Number(to.params.id) * 2, + other: to.query.q, + }), + }, }, ], }, @@ -203,6 +248,7 @@ describe('RouterView', () => { components: { default: components.User }, instances: {}, path: '/users/:id', + props, }, ], } diff --git a/__tests__/matcher/records.spec.ts b/__tests__/matcher/records.spec.ts index aa25b115..a49f9019 100644 --- a/__tests__/matcher/records.spec.ts +++ b/__tests__/matcher/records.spec.ts @@ -17,7 +17,7 @@ describe('normalizeRouteRecord', () => { meta: {}, name: undefined, path: '/home', - props: false, + props: { default: false }, }) }) @@ -41,7 +41,7 @@ describe('normalizeRouteRecord', () => { meta: { foo: true }, name: 'name', path: '/home', - props: false, + props: { default: false }, }) }) @@ -83,7 +83,7 @@ describe('normalizeRouteRecord', () => { meta: { foo: true }, name: 'name', path: '/home', - props: false, + props: { one: false }, }) }) }) diff --git a/__tests__/utils.ts b/__tests__/utils.ts index 225eca37..d93270fc 100644 --- a/__tests__/utils.ts +++ b/__tests__/utils.ts @@ -8,6 +8,7 @@ import { RouteComponent, RouteRecordRaw, RouteRecordName, + _RouteRecordProps, } from '../src/types' import { h, ComponentOptions } from 'vue' import { @@ -52,7 +53,7 @@ export interface RouteRecordViewLoose > { leaveGuards?: any instances: Record - props?: _RouteRecordBase['props'] + props: Record aliasOf: RouteRecordViewLoose | undefined } diff --git a/playground/router.ts b/playground/router.ts index b2a89f4a..2b030a54 100644 --- a/playground/router.ts +++ b/playground/router.ts @@ -25,7 +25,7 @@ export const router = createRouter({ { path: '/', components: { default: Home, other: component }, - props: to => ({ waited: to.meta.waitedFor }), + props: { default: to => ({ waited: to.meta.waitedFor }) }, }, { path: '/always-redirect', @@ -60,18 +60,18 @@ export const router = createRouter({ { path: '/children', name: 'WithChildren', - component, + component: Nested, children: [ - { path: '', alias: 'alias', name: 'default-child', component }, - { path: 'a', name: 'a-child', component }, + { path: '', alias: 'alias', name: 'default-child', component: Nested }, + { path: 'a', name: 'a-child', component: Nested }, { path: 'b', name: 'b-child', - component, + component: Nested, children: [ - { path: '', component }, - { path: 'a2', component }, - { path: 'b2', component }, + { path: '', component: Nested }, + { path: 'a2', component: Nested }, + { path: 'b2', component: Nested }, ], }, ], diff --git a/playground/views/Nested.vue b/playground/views/Nested.vue index 654a8388..d1a337a3 100644 --- a/playground/views/Nested.vue +++ b/playground/views/Nested.vue @@ -1,7 +1,7 @@