Skip to content

Commit 969b487

Browse files
committed
update docs
1 parent 563dbe6 commit 969b487

File tree

4 files changed

+65
-29
lines changed

4 files changed

+65
-29
lines changed

docs/guide/README.md

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,46 @@
1-
# Getting Started
1+
# Quickstart
2+
3+
```javascript
4+
import Vue from 'vue'
5+
import MiddlewarePlugin from 'vue-router-middleware-plugin'
6+
import router from '@/path-to-router'
7+
8+
Vue.use(MiddlewarePlugin, router)
9+
```
10+
11+
```javascript
12+
import store from '@/path-to-store'
13+
14+
export default ({ to, from, redirect }) => {
15+
if (!store.getters.isLoggedIn) {
16+
redirect('/login')
17+
}
18+
}
19+
```
20+
21+
```javascript
22+
import AuthMiddleware from '@/path-to-auth-middleware'
23+
24+
export default new VueRouter({
25+
routes: [
26+
{
27+
path: '/',
28+
meta: {
29+
middleware: AuthMiddleware
30+
},
31+
.
32+
.
33+
},
34+
{
35+
path: '/login',
36+
meta: {
37+
middleware: [LoggerMiddleware, AnalyticsMiddleware]
38+
},
39+
.
40+
.
41+
}
42+
]
43+
})
44+
```
45+
46+
Easy as that to get started. For advanced features continue to [configurations](/configurations).

docs/guide/configurations.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Configuration
2+
3+
```bash
4+
npm install --save vue-router-middleware-plugin
5+
```

docs/guide/context.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@ export default context => {
1212
}
1313
```
1414

15+
## Custom Context
16+
1517
It always contain a few built-in properties but can also be extended to include [custom properties](/api/context.html#adding-custom-properties) as per use case.

docs/guide/usage.md renamed to docs/guide/middlewares.md

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,6 @@
1-
# Usage
1+
# Middlewares
22

3-
## Concept
4-
5-
## Types of middlewares
6-
7-
### Global Middlewares
8-
9-
```javascript
10-
Vue.use(MiddlewarePlugin, {
11-
router,
12-
middleware: AuthMiddleware
13-
})
14-
15-
// or
16-
17-
Vue.use(MiddlewarePlugin, {
18-
router,
19-
middleware: [AuthMiddleware, AnalyticsMiddleware]
20-
})
21-
```
22-
23-
### Route Middlewares
3+
## Route Middleware
244

255
```javascript
266
const routes = [
@@ -66,14 +46,18 @@ const routes = [
6646
]
6747
```
6848

69-
## Use Cases
70-
71-
### Route Protection
49+
## Global Middleware
7250

7351
```javascript
74-
```
52+
Vue.use(MiddlewarePlugin, {
53+
router,
54+
middleware: AuthMiddleware
55+
})
7556

76-
### Long Running Tasks
57+
// or
7758

78-
```javascript
59+
Vue.use(MiddlewarePlugin, {
60+
router,
61+
middleware: [AuthMiddleware, AnalyticsMiddleware]
62+
})
7963
```

0 commit comments

Comments
 (0)