Migrating from 2.x to 3.x

New features

  • When a transition fails (either in a canActivate, canDeactivate or middleware function), a custom error can be returned containing a redirect property.
  • Persistent parameters plugin now available.

Breaking change

There are no breaking changes.

Code example

Redirecting to a login page if the current user is not logged in:
1
// With promises
2
router.canActivate(
3
'profile',
4
() => isLoggedIn()
5
.catch(() => ({ redirect: { name: 'login' } }))
6
);
7
8
// With callbacks
9
router.canActivate(
10
'profile',
11
(toState, fromState, done) => {
12
isLoggedIn()
13
.then(() => done(null, toState))
14
.catch(() => done(({ redirect: { name: 'login' } })))
15
}
16
);
Copied!