Skip to content

Commit 19a56fe

Browse files
committed
rename canActivate/canDeactivate to beforeEnter/beforeLeave
1 parent 1095045 commit 19a56fe

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

examples/navigation-guards/app.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function guardRoute (route, redirect, next) {
2121
}
2222
}
2323

24-
// Baz implements an in-component canDeactivate hook
24+
// Baz implements an in-component beforeRouteLeave hook
2525
const Baz = {
2626
data () {
2727
return { saved: false }
@@ -32,7 +32,7 @@ const Baz = {
3232
<button @click="saved = true">save</button>
3333
</div>
3434
`,
35-
routeCanDeactivate (route, redirect, next) {
35+
beforeRouteLeave (route, redirect, next) {
3636
if (this.saved || window.confirm('Not saved, are you sure you want to navigate away?')) {
3737
next()
3838
}
@@ -45,8 +45,8 @@ const router = new VueRouter({
4545
routes: [
4646
{ path: '/', component: Home },
4747

48-
// inline canActivate
49-
{ path: '/foo', component: Foo, canActivate: guardRoute },
48+
// inline guard
49+
{ path: '/foo', component: Foo, beforeEnter: guardRoute },
5050

5151
// using meta properties on the route config
5252
// and check them in a global before hook

flow/declarations.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ declare type RouteConfig = {
2323
redirect?: RedirectOption;
2424
alias?: string | Array<string>;
2525
children?: Array<RouteConfig>;
26-
canActivate?: Function;
27-
canDeactivate?: Function;
26+
beforeEnter?: Function;
27+
beforeLeave?: Function;
2828
meta?: any;
2929
}
3030

@@ -36,8 +36,8 @@ declare type RouteRecord = {
3636
parent: ?RouteRecord;
3737
redirect: ?RedirectOption;
3838
matchAs: ?string;
39-
canActivate: ?Function;
40-
canDeactivate: ?Function;
39+
beforeEnter: ?Function;
40+
beforeLeave: ?Function;
4141
meta: any;
4242
}
4343

src/create-route-map.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ function addRouteRecord (
3838
parent,
3939
matchAs,
4040
redirect: route.redirect,
41-
canActivate: route.canActivate,
42-
canDeactivate: route.canDeactivate,
41+
beforeEnter: route.beforeEnter,
42+
beforeLeave: route.beforeLeave,
4343
meta: route.meta || {}
4444
}
4545

src/history/base.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ function extractRouteGuards (
142142
matched: Array<RouteRecord>,
143143
deactivate: boolean
144144
): Array<?Function> {
145-
const inlineGuardKey = deactivate ? 'canDeactivate' : 'canActivate'
146-
const compGuardKey = deactivate ? 'routeCanDeactivate' : 'routeCanActivate'
145+
const inlineGuardKey = deactivate ? 'beforeLeave' : 'beforeEnter'
146+
const compGuardKey = deactivate ? 'beforeRouteLeave' : 'beforeRouteEnter'
147147

148148
const guards = matched.map(m => {
149149
const inlineGuard = m[inlineGuardKey]

0 commit comments

Comments
 (0)