From 85f2f83cf2b77a598d175a5d67322661b618aea3 Mon Sep 17 00:00:00 2001 From: Victor Saa <45251845+vis97c@users.noreply.github.com> Date: Tue, 12 Apr 2022 04:09:45 -0500 Subject: [PATCH] feat: route alias support (#4273) --- docs/content/2.guide/3.directory-structure/10.pages.md | 4 ++++ packages/nuxt3/src/pages/utils.ts | 1 + 2 files changed, 5 insertions(+) diff --git a/docs/content/2.guide/3.directory-structure/10.pages.md b/docs/content/2.guide/3.directory-structure/10.pages.md index 094edca48b..319e7b0877 100644 --- a/docs/content/2.guide/3.directory-structure/10.pages.md +++ b/docs/content/2.guide/3.directory-structure/10.pages.md @@ -277,6 +277,10 @@ You can define middleware to apply before loading this page. It will be merged w You can define transition properties for the `` components that wraps your pages and layouts, or pass `false` to disable the `` wrapper for that route. You can see a list of options that can be passed [here](https://vuejs.org/api/built-in-components.html#transition) or read [more about how transitions work](https://vuejs.org/guide/built-ins/transition.html#transition). +#### `alias` + +You can define page aliases. They allow you to access the same page from different paths. It can be either a string or an array of string as defined [here](https://router.vuejs.org/guide/essentials/redirect-and-alias.html#alias) on vue-router documentation. + ## Navigation To navigate between pages of your app, you should use the [``](/api/components/nuxt-link) component. diff --git a/packages/nuxt3/src/pages/utils.ts b/packages/nuxt3/src/pages/utils.ts index ba5c2c6b92..8d01d12024 100644 --- a/packages/nuxt3/src/pages/utils.ts +++ b/packages/nuxt3/src/pages/utils.ts @@ -237,6 +237,7 @@ export function normalizeRoutes (routes: NuxtPage[], metaImports: Set = ...Object.fromEntries(Object.entries(route).map(([key, value]) => [key, JSON.stringify(value)])), children: route.children ? normalizeRoutes(route.children, metaImports).routes : [], meta: route.meta ? `{...(${metaImportName} || {}), ...${JSON.stringify(route.meta)}}` : metaImportName, + alias: `${metaImportName}.alias || []`, component: genDynamicImport(file) } }))