Skip to content

Commit 16066fd

Browse files
refactor(routing): refactored advanced routing section.
1 parent 3293585 commit 16066fd

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

content/vue-router/advanced.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,28 @@ They are primarily used to guard navigations either by redirecting it or canceli
4949
11. DOM updates triggered.
5050
12. Call callbacks passed to `next` in `beforeRouteEnter` guards with instantiated instances.
5151

52+
Every guard function receives two arguments:
53+
54+
`to`: the target route location in a normalized format being navigated to.
55+
56+
`from`: the current route location in a normalized format being navigated away from.
57+
58+
## RouterView slot
59+
60+
The RouterView component exposes a slot that can be used to render the route component
61+
62+
```vue
63+
<template>
64+
<router-view v-slot="{ Component }">
65+
<transition>
66+
<keep-alive>
67+
<component :is="Component" :some-prop="prop"/>
68+
</keep-alive>
69+
</transition>
70+
</router-view>
71+
</template>
72+
```
73+
5274
## Transitions
5375

5476
```vue
@@ -90,3 +112,30 @@ const routes = [
90112
</RouterView>
91113
</template>
92114
```
115+
116+
## Route Meta fields
117+
118+
Attach arbitrary information to routes like: transition names, or roles to control who can access the route, etc.
119+
120+
```js
121+
const routes = [
122+
{
123+
path: '/posts',
124+
component: PostsLayout,
125+
children: [
126+
{
127+
path: 'new',
128+
component: PostsNew,
129+
// only authenticated users can create posts
130+
meta: { requiresAuth: true },
131+
},
132+
{
133+
path: ':id',
134+
component: PostsDetail,
135+
// anybody can read a post
136+
meta: { requiresAuth: false },
137+
},
138+
],
139+
},
140+
]
141+
```

0 commit comments

Comments
 (0)