router5
  • Read Me
  • Introduction
    • Why router5?
    • Getting Started
    • Ecosystem
    • Core concepts
    • Transition phase
  • Guides
    • Defining routes
    • Path Syntax
    • Router options
    • Navigating
    • In the browser
    • Observing state
  • Integration
    • With React
    • With Redux
  • Advanced
    • Plugins
    • Middleware
    • Preventing navigation
    • Errors and redirections
    • Dependency injection
    • Loading async data
    • Universal routing
    • Listeners plugin
  • API Reference
  • Migration
    • Migrating from 7.x to 8.x
    • Migrating from 6.x to 7.x
    • Migrating from 5.x to 6.x
    • Migrating from 4.x to 5.x
    • Migrating from 3.x to 4.x
    • Migrating from 2.x to 3.x
    • Migrating from 1.x to 2.x
    • Migrating from 0.x to 1.x
Powered by GitBook
On this page
  • New features
  • Breaking change
  • Code example
  1. Migration

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:

// With promises
router.canActivate(
    'profile',
    () => isLoggedIn()
        .catch(() => ({ redirect: { name: 'login' } }))
);

// With callbacks
router.canActivate(
    'profile',
    (toState, fromState, done) => {
        isLoggedIn()
            .then(() => done(null, toState))
            .catch(() => done(({ redirect: { name: 'login' } })))
    }
);
PreviousMigrating from 3.x to 4.xNextMigrating from 1.x to 2.x

Last updated 7 years ago