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