From 83a959a67b71333f2ae2eaa358b64abe22d619b9 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Mon, 24 Jan 2022 10:35:28 +0000 Subject: [PATCH] fix(nuxt3): allow customising page keys (#2859) --- .../3.docs/2.directory-structure/9.pages.md | 27 +++++++++++++++++++ examples/with-pages/app.vue | 6 +++++ .../with-pages/pages/parent/reload-[id].vue | 13 +++++++++ .../with-pages/pages/parent/static-[id].vue | 10 +++++++ .../nuxt3/src/pages/runtime/composables.ts | 1 + .../nuxt3/src/pages/runtime/nested-page.vue | 26 +++++++++++++++--- packages/nuxt3/src/pages/runtime/page.vue | 2 +- 7 files changed, 81 insertions(+), 4 deletions(-) create mode 100644 examples/with-pages/pages/parent/reload-[id].vue create mode 100644 examples/with-pages/pages/parent/static-[id].vue diff --git a/docs/content/3.docs/2.directory-structure/9.pages.md b/docs/content/3.docs/2.directory-structure/9.pages.md index 0401de416f..ab5b20b7f1 100644 --- a/docs/content/3.docs/2.directory-structure/9.pages.md +++ b/docs/content/3.docs/2.directory-structure/9.pages.md @@ -134,6 +134,29 @@ To display the `child.vue` component, you have to insert the ` ``` +### Child route keys + +If you want more control over when the `` component is re-rendered (for example, for transitions), you can either pass a string or function via the `childKey` prop, or you can define a `key` value via `definePageMeta`: + +```html{}[pages/parent.vue] + +``` + +Or alternatively: + +```html{}[pages/child.vue] + +``` + ## Page Metadata You might want to define metadata for each route in your app. You can do this using the `definePageMeta` macro, which will work both in ` diff --git a/examples/with-pages/pages/parent/static-[id].vue b/examples/with-pages/pages/parent/static-[id].vue new file mode 100644 index 0000000000..da1aaa7e2e --- /dev/null +++ b/examples/with-pages/pages/parent/static-[id].vue @@ -0,0 +1,10 @@ + + + diff --git a/packages/nuxt3/src/pages/runtime/composables.ts b/packages/nuxt3/src/pages/runtime/composables.ts index dcaa7ce58d..14defaa2b6 100644 --- a/packages/nuxt3/src/pages/runtime/composables.ts +++ b/packages/nuxt3/src/pages/runtime/composables.ts @@ -14,6 +14,7 @@ export interface PageMeta { [key: string]: any transition?: false | TransitionProps layout?: false | string | Ref | ComputedRef + key?: string | ((route: RouteLocationNormalizedLoaded) => string) // TODO: https://github.com/vuejs/vue-next/issues/3652 // keepalive?: false | KeepAliveProps } diff --git a/packages/nuxt3/src/pages/runtime/nested-page.vue b/packages/nuxt3/src/pages/runtime/nested-page.vue index 52837785e8..f1602b4865 100644 --- a/packages/nuxt3/src/pages/runtime/nested-page.vue +++ b/packages/nuxt3/src/pages/runtime/nested-page.vue @@ -1,11 +1,31 @@ - diff --git a/packages/nuxt3/src/pages/runtime/page.vue b/packages/nuxt3/src/pages/runtime/page.vue index 0238f8c807..6548728f8b 100644 --- a/packages/nuxt3/src/pages/runtime/page.vue +++ b/packages/nuxt3/src/pages/runtime/page.vue @@ -3,7 +3,7 @@ - +