Skip to content

Commit 011cb40

Browse files
committed
docs: redirect records
Close #107
1 parent f7f29e4 commit 011cb40

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

docs/guide/extending-routes.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ const router = createRouter({
108108
})
109109
```
110110

111-
As this plugin evolves, this should be used less and less and only become necessary in unique edge cases.
111+
As this plugin evolves, this should be used less and less and only become necessary in specific scenarios.
112112

113113
One example of this is using [vite-plugin-vue-layouts](https://github.com/JohnCampionJr/vite-plugin-vue-layouts) which can only be used this way:
114114

@@ -122,3 +122,21 @@ const router = createRouter({
122122
routes: setupLayouts(routes),
123123
})
124124
```
125+
126+
Another one is adding _redirect_ records to the router:
127+
128+
```ts
129+
import { routes } from 'vue-router/auto-routes'
130+
131+
routes.push({
132+
path: '/path-to-redirect',
133+
redirect: '/redirected-path',
134+
})
135+
136+
routes.push({
137+
path: '/path-to-redirect/:id',
138+
redirect: (to) => `/redirected-path/${to.params.id}`,
139+
})
140+
```
141+
142+
One benefit of adding redirects at runtime only is that they are not reflected in the generated `typed-router.d.ts` and won't appear in autocompletion but will still work as expected when the user enters the URL or clicks on a link.

0 commit comments

Comments
 (0)