Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export type { Routes, RouteOptionParams, PathParamOptions } from './router'
export { RouterProvider } from './context'

export { useRedirect, Redirect } from './redirect'
export type { RedirectProps, UseRedirectProps } from './redirect'
export type { RedirectProps } from './redirect'

export { Link, ActiveLink } from './Link'

Expand Down
21 changes: 6 additions & 15 deletions src/redirect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,13 @@ import { useLayoutEffect } from 'react'

import { getCurrentHash, usePath } from './location'
import { navigate, NavigateOptions } from './navigate'
import { QueryParam, useQueryParams } from './querystring'
import { useQueryParams } from './querystring'

export interface RedirectProps extends NavigateOptions {
to: string
merge?: boolean
}

export interface UseRedirectProps {
predicateUrl: string
targetUrl: string
queryParams?: QueryParam | URLSearchParams
replace?: boolean
state?: unknown
}

export function Redirect({
to,
query,
Expand All @@ -28,15 +20,14 @@ export function Redirect({
return null
}

export interface UseRedirectOptions extends NavigateOptions {
merge?: boolean
}

export function useRedirect(
predicateUrl: string | null,
targetUrl: string,
{
query,
replace = true,
merge = true,
state,
}: { query?: QueryParam; replace?: boolean; merge?: boolean; state?: unknown } = {},
{ query, replace = true, merge = true, state }: UseRedirectOptions = {},
): void {
const currentPath = usePath()
const [currentQuery] = useQueryParams()
Expand Down
Loading