Skip to content

Commit

Permalink
docs: redirect records
Browse files Browse the repository at this point in the history
Close #107
  • Loading branch information
posva committed Aug 20, 2024
1 parent f7f29e4 commit 011cb40
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion docs/guide/extending-routes.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ const router = createRouter({
})
```

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

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:

Expand All @@ -122,3 +122,21 @@ const router = createRouter({
routes: setupLayouts(routes),
})
```

Another one is adding _redirect_ records to the router:

```ts
import { routes } from 'vue-router/auto-routes'

routes.push({
path: '/path-to-redirect',
redirect: '/redirected-path',
})

routes.push({
path: '/path-to-redirect/:id',
redirect: (to) => `/redirected-path/${to.params.id}`,
})
```

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 comments on commit 011cb40

Please sign in to comment.