@profiscience/knockout-contrib-router-plugins-redirect
v2.0.17
Published
[![Version][npm-version-shield]][npm] [![Dependency Status][david-dm-shield]][david-dm] [![Peer Dependency Status][david-dm-peer-shield]][david-dm-peer] [![Dev Dependency Status][david-dm-dev-shield]][david-dm-dev] [![Downloads][npm-stats-shield]][npm-sta
Downloads
42
Readme
router.plugins.redirect
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'
},
})