@profiscience/knockout-contrib-router-plugins-redirect
TypeScript icon, indicating that this package has built-in type declarations

2.0.17 • Public • Published

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'
  },
})

Readme

Keywords

none

Package Sidebar

Install

npm i @profiscience/knockout-contrib-router-plugins-redirect

Weekly Downloads

7

Version

2.0.17

License

WTFPL

Unpacked Size

20.2 kB

Total Files

12

Last publish

Collaborators

  • dorgeron
  • barsh