You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
add function `redirect` to middleware context
BREAKING CHANGE: 1. No need to resolve every middleware by calling context functin `next` 2. `next`
is removed from middleware context.
Copy file name to clipboardExpand all lines: README.md
+32-19Lines changed: 32 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -36,15 +36,19 @@ Create a middleware, `auth.js`
36
36
```javascript
37
37
importstorefrom'~/store'
38
38
39
-
exportdefault ({ to, from, next }) => {
40
-
if (store.getters.isLoggedIn) {
41
-
next()
42
-
} else {
43
-
next('/login')
39
+
exportdefault ({ to, from, redirect }) => {
40
+
if (!store.getters.isLoggedIn) {
41
+
redirect('/login')
42
+
// or
43
+
redirect(from)
44
+
// or
45
+
redirect(false)
44
46
}
45
47
}
46
48
```
47
49
50
+
> **Note:** Properties `to` and `from` are the same as in a vue router navigation gaurds. In __v2.0.0__ functin `next` has been replaced by `redirect` which can be called to redirect to a route. Now, there's no need to call `next` in each middleware to resolve it.
51
+
48
52
Register the plugin in your application.
49
53
50
54
```javascript
@@ -56,13 +60,14 @@ import LoggerMiddleware from '~router/middlewares/logger'
0 commit comments