one
Version:
One is a new React Framework that makes Vite serve both native and web.
17 lines (14 loc) • 486 B
text/typescript
import { getURL } from '../getURL'
import type { OneRouter } from '../interfaces/router'
import { router } from '../router/imperative-api'
export const redirect = (
path: '__branded__' extends keyof OneRouter.Href ? string : OneRouter.Href,
status?: number
) => {
if (process.env.VITE_ENVIRONMENT === 'client') {
router.navigate(path)
return
}
const finalPath = path[0] === '/' ? `${getURL()}${path}` : path
return Response.redirect(finalPath as string, status)
}