knockout-contrib

:metal: KnockoutJS Goodies Monorepo

View the Project on GitHub Profiscience/knockout-contrib

router.plugins.redirect

Version Dependency Status Peer Dependency Status Dev Dependency Status Downloads

Support redirect option in route configurations.

Usage

Redirects to the returned path, if any. Supports async via promise.

import { Route, redirectRoutePlugin } from '@profiscience/knockout-contrib'

Route.usePlugin(redirectRoutePlugin)

function shouldRedirect(ctx) {
  // ...do something...
}

// Sync
new Route('/', {
  redirect: (ctx) => {
    if (shouldRedirect(ctx)) return '//redirect/to/this/route'
  },
})

// Async
new Route('/', {
  redirect: async (ctx) => {
    if (await shouldRedirect(ctx)) return '//redirect/to/this/route'
  },
})