Skip to content

Commit b2d3941

Browse files
committed
docs: improve examples without component option
1 parent 42bee8c commit b2d3941

File tree

5 files changed

+30
-12
lines changed

5 files changed

+30
-12
lines changed

docs/guide/advanced/transitions.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,16 @@ The above usage will apply the same transition for all routes. If you want each
1818

1919
```js
2020
const routes = [
21-
{ path: '/custom-transition', meta: { transition: 'slide-left' } },
22-
{ path: '/other-transition', meta: { transition: 'slide-right' } },
21+
{
22+
path: '/custom-transition',
23+
component: PanelLeft,
24+
meta: { transition: 'slide-left' },
25+
},
26+
{
27+
path: '/other-transition',
28+
component: PanelRight,
29+
meta: { transition: 'slide-right' },
30+
},
2331
]
2432
```
2533

docs/guide/essentials/dynamic-matching.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ Regular params will only match characters in between url fragments, separated by
8282
```js
8383
const routes = [
8484
// will match everything and put it under `$route.params.pathMatch`
85-
{ path: '/:pathMatch(.*)*', name: 'NotFound' },
85+
{ path: '/:pathMatch(.*)*', name: 'NotFound', component: NotFound },
8686
// will match anything starting with `/user-` and put it under `$route.params.afterUser`
87-
{ path: '/user-:afterUser(.*)' },
87+
{ path: '/user-:afterUser(.*)', component: UserGeneric },
8888
]
8989
```
9090

docs/guide/essentials/redirect-and-alias.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ const routes = [
3636

3737
Note that **[Navigation Guards](../advanced/navigation-guards.md) are not applied on the route that redirects, only on its target**. e.g. In the example below, adding a `beforeEnter` guard to the `/home` route would not have any effect.
3838

39+
When writing a `redirect`, you can omit the `component` option because it is never directly reached so there is no component to render. The only exception are [nested routes](./nested-routes.md): if a route record has `children` and a `redirect` property, it should also have a `component` property.
40+
3941
### Relative redirecting
4042

4143
It's also possible to redirect to a relative ___location:
@@ -70,6 +72,7 @@ An alias gives you the freedom to map a UI structure to an arbitrary URL, instea
7072
const routes = [
7173
{
7274
path: '/users',
75+
component: UsersLayout,
7376
children: [
7477
// this will render the UserList for these 3 URLs
7578
// - /users
@@ -87,6 +90,7 @@ If your route has parameters, make sure to include them in any absolute alias:
8790
const routes = [
8891
{
8992
path: '/users/:id',
93+
component: UsersByIdLayout,
9094
children: [
9195
// this will render the UserDetails for these 3 URLs
9296
// - /users/24

docs/guide/essentials/route-matching-syntax.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
Most applications will use static routes like `/about` and dynamic routes like `/users/:userId` like we just saw in [Dynamic Route Matching](./dynamic-matching.md), but Vue Router has much more to offer!
44

5+
:::tip
6+
For the sake of simplicity, all, route records **are omitting the `component` property** to focus on the `path` value.
7+
:::
8+
59
## Custom Regexp in params
610

711
When defining a param like `:userId`, we internally use the following regexp `([^/]+)` (at least one character that isn't a slash `/`) to extract params from URLs. This works well unless you need to differentiate two routes based on the param content. Imagine two routes `/:orderId` and `/:productName`, both would match the exact same URLs, so we need a way to differentiate them. The easiest way would be to add a static section to the path that differentiates them:

docs/guide/migration/index.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ Pushing or resolving a named route without its required params will throw an err
3232

3333
```js
3434
// given the following route:
35-
const routes = [{ path: '/users/:id', name: 'users' }]
35+
const routes = [{ path: '/users/:id', name: 'user', component: UserDetails }]
3636

3737
// Missing the `id` param will fail
38-
router.push({ name: 'users' })
39-
router.resolve({ name: 'users' })
38+
router.push({ name: 'user' })
39+
router.resolve({ name: 'user' })
4040
```
4141

4242
**Reason**: Same as above.
@@ -50,9 +50,10 @@ const routes = [
5050
{
5151
path: '/dashboard',
5252
name: 'dashboard-parent',
53+
component: DashboardParent
5354
children: [
54-
{ path: '', name: 'dashboard' },
55-
{ path: 'settings', name: 'dashboard-settings' },
55+
{ path: '', name: 'dashboard', component: DashboardDefault },
56+
{ path: 'settings', name: 'dashboard-settings', component: DashboardSettings },
5657
],
5758
},
5859
]
@@ -70,10 +71,11 @@ This has an important side effect about children `redirect` records like these:
7071
const routes = [
7172
{
7273
path: '/parent',
74+
component: Parent,
7375
children: [
7476
// this would now redirect to `/home` instead of `/parent/home`
7577
{ path: '', redirect: 'home' },
76-
{ path: 'home' },
78+
{ path: 'home', component: Home },
7779
],
7880
},
7981
]
@@ -152,9 +154,9 @@ Catch all routes (`*`, `/*`) must now be defined using a parameter with a custom
152154
const routes = [
153155
// pathMatch is the name of the param, e.g., going to /not/found yields
154156
// { params: { pathMatch: ['not', 'found'] }}
155-
{ path: '/:pathMatch(.*)*', name: 'not-found' },
157+
{ path: '/:pathMatch(.*)*', name: 'not-found', component: NotFound },
156158
// if you omit the last `*`, the `/` character in params will be encoded when resolving or pushing
157-
{ path: '/:pathMatch(.*)', name: 'bad-not-found' },
159+
{ path: '/:pathMatch(.*)', name: 'bad-not-found', component: NotFound },
158160
]
159161
// bad example:
160162
router.resolve({

0 commit comments

Comments
 (0)